GCMIntentService的额外意图不通过 [英] Intent Extras of GCMIntentService is not passed
问题描述
I codeD GCMIntentService
而是叫活动
不能得到其他。
I coded GCMIntentService
but called Activity
cannot get the Extras.
@Override
protected void onMessage(Context context, Intent intent) {
Intent resultIntent = new Intent(this, MainActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
Intent.FLAG_ACTIVITY_SINGLE_TOP);
resultIntent.putExtra("PushType", "test"); // Put String Extra.
PendingIntent resultPendingIntent = PendingIntent.getActivity(this, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);
}
和名为 MainActivity
是如下codeD。
and called MainActivity
is coded as below.
@Override
protected void onResume() {
super.onResume();
final Intent receivedIntent = getIntent();
if (receivedIntent != null && receivedIntent.hasExtra("PushType")) {
// Breakpoint at here. but no Extras are given.
}
}
}
我在做断点 receivedIntent
和 mExtras
里面它显示为空。
此外,我称之为 MainActivity
清单是如下codeD。
Additionally, my called MainActivity
manifest is coded as below.
<activity
android:name=".MainActivity"
android:theme="@android:style/Theme.NoTitleBar"
android:configChanges="keyboardHidden|orientation|screenSize"
android:label="@string/app_name">
<intent-filter>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
我改叫意图另一个活动
并成功加载其他方案。
替代活动(其中包括成功额外)的表现是如下。
I changed called intent to another Activity
and it successfully loads Extras.
The manifest of substitute activity (which successfully contains Extras) was as below.
<activity
android:name=".NotificationActivity"
android:parentActivityName=".MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity"/>
</activity>
我是怎么了?
推荐答案
看起来你需要重写onNewIntent(意向意图)方法和内部onNewIntent()调用setIntent(意向)。然后onResume()将搭载新的意图。见<一href=\"http://developer.android.com/reference/android/app/Activity.html#onNewIntent%28android.content.Intent%29\"相对=nofollow> onNewIntent()了解详细信息。
It looks like you need to override onNewIntent(Intent intent) method and inside onNewIntent() call setIntent(intent). Then onResume() will pick up the new intent. See onNewIntent() for more detail.
这篇关于GCMIntentService的额外意图不通过的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!