3
我编码GCMIntentService
但叫Activity
无法获得额外。意图其他GCMIntentService不通过
@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
是编码如下。
@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
清单编码如下。
<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>
我改叫意图另一Activity
并成功加载其他方案。 替代活动的清单(成功包含Extras)如下。
<activity
android:name=".NotificationActivity"
android:parentActivityName=".MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity"/>
</activity>
我错了什么?
作品像魅力。谢谢:) – Youngjae
没问题,很高兴它现在可以工作:) – Y2i
我会在onMessage()中突出使用'PendingIntent.FLAG_UPDATE_CURRENT',因为没有它,现有的Intent会传递给onNewIntent(),并且它让这个新手感到困惑时间。 – markdwhite