在另一个Intent内发送Intent [英] Sending Intent inside of another Intent
问题描述
也许我用的是错误的方法,但是我想在自己的应用程序中响应我的Android AppWidget的click事件并启动一个Activity.设置PendingIntent
时,我还有另一个Intent
,我想在单击时启动它.我的onStartCommand
使用此行:
Perhaps I am going about this the wrong way, but I want to respond to my Android AppWidget's click event within my own app AND launch an Activity. At the time I set the PendingIntent
I have another Intent
which I want to launch when clicked. My onStartCommand
uses this line:
final Intent mLaunchIntent = (Intent) intent.getParcelableExtra(Widget.EXTRA_INTENT);
当我致电setOnClickPendingIntent
时,我之前有这条线:
When I call setOnClickPendingIntent
I have this line prior:
mSendingIntent.putExtra(Widget.EXTRA_INTENT, (Parcelable) mLaunchIntent);
因此,即使在两行中mLaunchIntent
是有效的Intent
,第一行仍会丢失大量数据.由于Intent
无效,因此调用startActivity
失败.
So even though mLaunchIntent
is a valid Intent
in both lines, the first line is missing a great deal of data. Calling startActivity
then fails because the Intent
is not valid.
我想知道是否有可能,以及如何在不严格调用putExtras
的情况下在另一个Intent
内部发送Intent
,因为该方法简单地将一个Intent
的额外内容添加到了下一个.我想将这两个分开并易于访问.
I am wondering if it is possible, and how, to send an Intent
inside of another Intent
without strictly calling putExtras
because that method simple adds the extras from one Intent
to the next. I'd like to keep these two separate and easily accessible.
推荐答案
我实际上已经弄清楚了,解决方案非常简单. mLaunchIntent
不应强制转换为Parcelable
,否则数据将丢失.
I actually figured it out, the solution was quite simple. mLaunchIntent
should not be cast to Parcelable
or the data gets lost.
mSendingIntent.putExtra(Intent.EXTRA_INTENT, mLaunchIntent);
这就是我通过另一个Intent
发送Intent
所需的全部内容.
That was all that I needed to send an Intent
through another Intent
.
这篇关于在另一个Intent内发送Intent的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!