Wednesday, June 13, 2012

Android - Refresh Parent Activity and Dialog (Activity) Results

When you're working with Android activities, sometimes you'll want to keep a 'parent' activity or main activity running instead of closing it with this.finish(). When you have this kind of activity, you also often want to refresh it when the child activity is complete.

This is the problem I ran into - I found that after I completed the 'child' activity, I didn't know what events were available for the parent activity to refresh.

The way I was starting the child activity was by using this.startActivity, like this:

Intent i = new Intent(PARENT_ACTIVITY.this, CHILD_ACTIVITY.class);

But if you do start the activity this way:

Intent i = new Intent( PARENT_ACTIVITY.this,  CHILD_ACTIVITY.class);
startActivityForResult(i, 0);

Then you can implement a method when the result is returned. The integer, in this case 0, helps you keep track of where you started the activity. Use a different constant value (or enum) for each type of activity you launch so you can easily keep track of it.

Here's a simple sample of the method you need to implement:

protected void onActivityResult(int requestCode, int resultCode, Intent data)
 That's it!

Also, you can look at the Intent and resultCode to get more information about what happened in the Activity. In the child activity, you have to call setResult(int) so it knows what resultCode to use. For more information about using onActivityResult like a 'DialogResult', visit Android's documentation on starting activities.

Also, if you don't have a 'parent' activity relationship, always remember to call this.finish() before starting an activity. Here's how I normally start an activity and end the current one:

        Intent i = new Intent( CURRENT_ACTIVITY.this, NEXT_ACTIVITY.class);

Thursday, July 7, 2011

How to view the SQLite database on your Android Emulator

This tutorial will show you how to open a SQLite datbase from your Android emulator.

This requires Eclipse and the Android plugin. If you don't have them, follow this tutorial.

This also requires a SQLite viewer. I used SQLite Database Browser.

Step 1

  • With Eclipse open and your emulator running
  • select the DDMS perspective by clicking on the Window -> Open Perspective -> DDMS menu option.

Step 1

Step 2

  • Select the emulator you have currently have running. 
  • Click the File Explorer tab
  • Find the data folder.

Step 2

Step 3

  • Follow the filepath to the application you want /data/data/
  • Click the Pull a file from the device button and save the database file on your computer.

Step 3

Step 4

  • Open the SQLite Database Viewer and click Open Database. 
  • Open the file and you can browse the data and view the schema!

Step 4

This can really help you debug some issues with your SQLite database!

With a few modifications, you should also be able to do this with your Android phone. The only problem I ran into was a permissions issue getting to the database file. I have not rooted my phone. There may also be other ways to get at it without rooting your phone.

Thursday, June 2, 2011

New HTML Schema Information for SEO

Google's Official Blog has just released an announcement about a new site,, for web developers to learn about HTML tags and attributes they can add to their HTML to identify content for Search Engines.

This isn't just Google's search engine, either. Bing and Yahoo were involved in the creation of and the new tags and attributes.

Getting Started has a page to help you get started. There is an example using the movie "Avatar" to show you how you can specify the data represents the movie and information about the movie.

There is also a full list of what you can specify.

Well, I think...

This looks great! If you are a site owner or developer, look into this now. It could open the floodgates for unique ways your site is displayed on search engines.

It can help your optimization in general as well. Imagine there were two people with the same name, an actor and a politician. You were writing an article about the politician. You can use the Person schema information to specify the organization they are involved with and their job title - valuable data that search engines can use to show your site to the correct search results!

It's like the Open Graph Protocol, but on steroids. The Open Graph Protocol helps you specify what the entire page is about. This goes many steps further - it helps you specify the content itself!