Android - Request code in onCreate [closed]

女生的网名这么多〃 提交于 2019-12-25 18:27:52

问题


can I access the requestCode an activity received in its onCreate() method?

I'd need it to understand if it is a "new" or "modify" operation.


回答1:


Let's say you create an activity A :

The activity lifecycle goes like this : A.onCreate() -> A.onStart() -> A.onResume()

Then you call activity B from activity A. You want activity B to send you back a result.

The activity lifecycle goes like this : A.onPause -> B.onCreate ->B.onStart()-> B.onResume()->A.onStop()

Once B has done its job, it will send a result and destroyed itself : B.onDestroy()->A.onResume()-> A.onActivityResultBack()

My whole point is that the activity A does not go back to onCreate ! So unless you have an attribute requestCode in your activityA.java file, you can not access it in its onCreate method.




回答2:


To see if it's a "new" or "modified" activity, you should override the onActivityResult method in the activity. If the onActivityResult is getting called, that means the activity is "modified".

See http://developer.android.com/training/basics/intents/result.html for how to use the onActivityResult.



来源:https://stackoverflow.com/questions/19219926/android-request-code-in-oncreate

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