OnActivityResult is not called when ListActivity ends

In the small application I'm working on, I need to select an entry from the database table.

To do this, I created a subclass of ListActivity , GameListScreen , which displays the entries and overrides onListItemClick() as follows:

 @Override protected void onListItemClick(ListView l, View v, int position, long id) { Game g = (Game)getListView().getItemAtPosition(position); Intent intent = new Intent(); intent.putExtra("id", g.getId()); setResult(RESULT_OK, intent); finish(); } 

Then, to start my activity, I have this in my MainMenu activity; a onClick for Button :

 public void openGameClick(View view) { Intent intent = new Intent(this, GameListScreen.class); startActivityForResult(intent, -1); } 

and get the result, also in the MainMenu class:

 @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == Activity.RESULT_OK) { // result is handled here } } 

Everything works exactly as expected - ListActivity starts, I can see my records, and when I select one, onListItemClick is executed, but onActivityResult does not receive the call, and I have no idea why. In another project, I adhere to the same basic principle, and it works there.

What am I missing here? I am sure this is a simple mistake, but I cannot notice it.

I uploaded my project in case this helps. I use Android 2.2 for testing, as this is what my phone uses.

+2
android listactivity
source share
1 answer

Perhaps that is why

From javadocs:

Run the action for which you want to get the result. When this action exits, your onActivityResult () method will be called with the given request code. Using a negative request The code is the same as calling startActivity (Intent) (the action does not start as a sub-activity).

+10
source share

All Articles