问题描述
我可以在我的应用程序启动的第一个活动欢迎画面,也可以由用户花费的时间。我希望它采取行动时,它从家庭开始略有不同的主要活动启动屏幕(或任何其他应用程序)或主要活动
I have a welcome screen that can be started as the first activity in my app, or it can be started by the main activity that the user spends their time in. I want it to act slightly differently when it's started from the home screen (or any other app) or the main activity.
调用 getCallingActivity()
中的onCreate似乎总是返回空值,不管是什么所谓的活动。这是奇怪的,因为它的工作较早,这是我发现了什么格式的字符串返回(这应该是在文档中是这样)。我看不出有什么可能影响它,因为调用之前出现这种情况的唯一的事情 getCallingActivity()
呼吁 super.onCreate(savedInstanceState)
。我打电话跟 startActivityForResult(welcomeIntent,RESULT_WELCOME)
。
Calling getCallingActivity()
in onCreate seems to always return null, regardless of what called the activity. This is strange, because it did work earlier, which is how I found what format the string returns in (which should be in the documentation anyway). I can't see what could have affected it, because the only thing that happens before calling getCallingActivity()
is calling super.onCreate(savedInstanceState)
. I am calling the activity with startActivityForResult(welcomeIntent, RESULT_WELCOME)
.
我是什么做错了吗?是否有其他方式来获得这些信息?
What am I doing wrong? Is there an alternative way to get this info?
推荐答案
传递一个额外的意图
与 startActivityForResult()使用
,说明你想要的模式。阅读额外通过 getIntent()。getXXXExtra()
( XXX
要看你选择什么样的数据类型)的的onCreate()
新开工活动。
Pass an extra in the Intent
used with startActivityForResult()
, indicating which mode you want. Read that extra via getIntent().getXXXExtra()
(XXX
depends on what data type you choose) in onCreate()
of the newly-started activity.
这篇关于为什么getCallingActivity总是返回null?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!