这是我的代码:
GCMIntentService:
Intent notificationIntent = new Intent(this, MainActivity.class);
notificationIntent.setAction(Intent.ACTION_MAIN);
notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER);
notificationIntent.putExtra("screen", activityToShow);
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent intent2 = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder nBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(smallIconToDisplayInGCM)
.setLargeIcon(largeIconToDisplayInGCM)
.setContentTitle(title)
.setContentText(text)
.setSound(sound)
.setTicker(ticker)
.setContentIntent(intent2)
.setAutoCancel(true);
Run Code Online (Sandbox Code Playgroud)
主要活动:
的onCreate()
onNewIntent(getIntent())
Run Code Online (Sandbox Code Playgroud)
onCreate()之外的新方法
@Override
public void onNewIntent(Intent intent){
Bundle extras = intent.getExtras();
String tabNumber = "";
if(extras != null) {
tabNumber = extras.getString("screen");
Log.d("TEMP", "Tab Number: " + tabNumber);
if(tabNumber.equals("") || (tabNumber == null)) {
// Set the active tab to be the Home …Run Code Online (Sandbox Code Playgroud)