Android:点击推送通知时如何调用函数

时间:2013-12-20 10:43:26

标签: android notifications google-cloud-messaging

void onReceive(Context context, Intent intent){
    try {
        GoogleCloudMessaging gcm=GoogleCloudMessaging.getInstance(context);
        Bundle bundle=intent.getExtras();
        sendNotification();
        showPage();
    }
}

当我点击推送通知时如何调用showPage(),否则不应该调用?

1 个答案:

答案 0 :(得分:0)

您可以执行类似

的操作
 Intent intent = new Intent(this, DemoActivity.class);
 intent.putExtra("tag", 1);
 PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);

这会致电您的DemoActivity。您现在必须获得意图并检查是否添加了Extras

Intent intent = getIntent();
    if(intent.getIntExtra("tag", 0) == 1) {
        showpage();
}