Android的 - 请求code中的onCreateAndroid、code、onCreate

2023-09-12 06:10:00 作者:纵马山川剑自提

我是否能访问请求,code活动在其的onCreate()方法获得?

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.

推荐答案

假设你创建活动的 A

活动的生命周期是这样的: A.onCreate() - GT; A.onStart() - > A.onResume()

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

然后调用活动的 B 从活动的 A 。你想活动的 B 给你送回来的结果。

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

活动的生命周期是这样的: A.onPause - > B.onCreate - > B.onStart() - > B.onResume() - > A.onStop()

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

在 B 已完成其工作,它将发送一个结果,并摧毁了自己: B.onDestroy() - > A.onResume() - > A.onActivityResultBack()

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

我的整个观点是,该活动的 A 不回去的onCreate !所以,除非你有一个属性请求,code在你的 activityA.java 的文件,你不能访问它在其的onCreate 方法。

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.