打开从 gcmIntentClass 到片段的通知 class
opening notofication from gcmIntentClass to a fragment class
我收到了来自 GCM
的通知...在我的 GcmIntentService class 中我这样做了。
Intent notificationIntent = new Intent(GcmIntentService.this,
HomeActivity.class);
当我点击通知时,我希望它打开 Fragment
..... 我在 HomeActivity.class 中有我的 Fragments
,我想从中打开消息 Fragment
.
Intent notificationIntent = new Intent(GcmIntentService.this,
HomeActivity.class );
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
PendingIntent resultPendingIntent =
PendingIntent.getActivity(GcmIntentService.this, 0, notificationIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder.setContentIntent(resultPendingIntent);
你可以像这样Intent
传递参数
notificationIntent.putExtra("fragment", 1);
其中 1 是您的片段索引,在您的 HomeActivity
中您可以使用此
int id=getIntent().getIntExtra("fragment", 0);
viewPager.setCurrentItem(id);
我收到了来自 GCM
的通知...在我的 GcmIntentService class 中我这样做了。
Intent notificationIntent = new Intent(GcmIntentService.this,
HomeActivity.class);
当我点击通知时,我希望它打开 Fragment
..... 我在 HomeActivity.class 中有我的 Fragments
,我想从中打开消息 Fragment
.
Intent notificationIntent = new Intent(GcmIntentService.this,
HomeActivity.class );
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
PendingIntent resultPendingIntent =
PendingIntent.getActivity(GcmIntentService.this, 0, notificationIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder.setContentIntent(resultPendingIntent);
你可以像这样Intent
传递参数
notificationIntent.putExtra("fragment", 1);
其中 1 是您的片段索引,在您的 HomeActivity
中您可以使用此
int id=getIntent().getIntExtra("fragment", 0);
viewPager.setCurrentItem(id);