Android: startActivityForResult always gets a resu

2019-05-13 16:13发布

For some reason, when I use the call, the result is always returned as 0. All I am doing is popup the selection box and then once the selection is made, the user hits the back button. Does anyone know what mistake I could be doing?

CALLING ACTIVITY:

Intent i = new Intent(this, Selection.class);
Log.d("Front-End", "Launching Activity");
startActivityForResult(i, SELECTION);

INVOKED ACTIVITY:

bundle.putStringArray("selections", selected_array);
Intent resultIntent = new Intent();
resultIntent.putExtras(bundle);
setResult(RESULT_OK, resultIntent);
finish();

Any suggestions? If I include the finish() call, it gives me the following:

W/ActivityManager( 1030): Duplicate finish request for HistoryRecord{44802c90 com.android.TVitter/.Selection}

2条回答
劫难
2楼-- · 2019-05-13 16:43

You could also implement Activity.onBackPressed() if you want to return some specific data from the activity when the back button is pressed. It looks like that's only available with 2.0 though.

查看更多
smile是对你的礼貌
3楼-- · 2019-05-13 16:57

Ok don't flame at me now. It took me two hours to debug this :( Just writing it down so that others won't make this stupid mistake. I had to put an "OK" button and then handle the event instead of letting the user press the "Back" button on the phone. It was an obvious thing but for some reason I missed it...

查看更多
登录 后发表回答