Android: startActivityForResult always gets a resultCode of 0? [closed]

匿名 (未验证) 提交于 2019-12-03 09:02:45

问题:

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} 

回答1:

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...



回答2:

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.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!