从获取的onCreate的意图在Android中 [英] Get the intent from onCreate in Android

查看:158
本文介绍了从获取的onCreate的意图在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 the Activity.

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 override onNewIntent() and collect the Intent there.

Another possibility is that you originally created a PendingIntent for the Intent with no extras, then later tried to create a new PendingIntent on an equivalent Intent (e.g., identifying the same activity) and included extras. In that case, you need to include FLAG_UPDATE_CURRENT or FLAG_CANCEL_CURRENT when creating the PendingIntent, so your new/changed extras are taken into account.

这篇关于从获取的onCreate的意图在Android中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆