从获取的onCreate的意图在Android中 [英] Get the intent from onCreate in Android
问题描述
我发起一个活动,从使用意图一些额外的部件我,反正我只可以得到意向时,活动背景。我怎样才能做的目的是创建活动时?与this.getIntent(尝试),但演员是空的。
在此先感谢
我怎样才能创建活动时的意图是什么?
块引用>呼叫
getIntent()
在活动
。
与this.getIntent(尝试),但演员是空的。
块引用>一种可能是你安排的活动的现有实例返回到前台(例如,包括
FLAG_ACTIVITY_REORDER_TO_FRONT
),在这种情况下,你将需要重写onNewIntent()
和收集意图
那里。另一种可能是您最初创建一个
的PendingIntent
为意图
没有额外,再后来试图建立一个新的的PendingIntent
上的等效意图
(例如,识别相同的活动),其中包括临时演员。在这种情况下,你需要包括FLAG_UPDATE_CURRENT
或创建时,FLAG_CANCEL_CURRENT
的的PendingIntent
,因此新的/改变演员都考虑在内。I launch an activity from my widget using an Intent with some extra, anyway I can only get the Intent when the activity is in background.. How can I get the Intent when activity is created? Tried with this.getIntent() but extras are null.
Thanks in advance
解决方案How can I get the Intent when activity is created?
Call
getIntent()
on theActivity
.Tried with this.getIntent() but extras are null.
One possibility is that you are arranging for an existing instance of the activity to return to the foreground (e.g., including
FLAG_ACTIVITY_REORDER_TO_FRONT
), in which case you will need to overrideonNewIntent()
and collect theIntent
there.Another possibility is that you originally created a
PendingIntent
for theIntent
with no extras, then later tried to create a newPendingIntent
on an equivalentIntent
(e.g., identifying the same activity) and included extras. In that case, you need to includeFLAG_UPDATE_CURRENT
orFLAG_CANCEL_CURRENT
when creating thePendingIntent
, so your new/changed extras are taken into account.这篇关于从获取的onCreate的意图在Android中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!