3

1.从通知栏打开 2.按home 返回desttop 3.从应用图标打开

问题:2个SampleTabsDefault实例,需要退出两次。

    Intent intent = new Intent(_context, SampleTabsDefault.class);
    intent.setFlags(/*Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP |*/ Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent activity = PendingIntent.getActivity(_context, 0, intent, 0);
    notification.contentIntent = activity;
4

2 回答 2

4

使用以下方法传递通知生成器的内容意图

private  PendingIntent getEmptyPendingIntent(Context context) {
    Intent resultIntent = new Intent(context, InitializationActivity.class);
    resultIntent.setAction(Long.toString(System.currentTimeMillis())); //adding unique identification for each intent
    resultIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    resultIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    stackBuilder.addParentStack(InitializationActivity.class);
    stackBuilder.addNextIntent(resultIntent);
    stackBuilder.getIntentCount();
    PendingIntent resultPendingIntent =
            stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

    return resultPendingIntent;
}

使用以下方法发送通知

private void sendNotification(String title, String message) {
    Intent intent = new Intent(this, InitializationActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    String desc = "";
    if (!TextUtils.isEmpty(message)) {
        try {
            JSONObject jsonObject = new JSONObject(message);
            desc = jsonObject.optString("payload");
                        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 , intent,
            PendingIntent.FLAG_ONE_SHOT);
    Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.ic_launcher)getResources().getDrawable(R.drawable.notify_large)).getBitmap())
            .setContentTitle(title)
            .setContentText(desc)
            .setAutoCancel(true)
            .setSound(defaultSoundUri)
            .setContentIntent(getEmptyPendingIntent(this));

    NotificationManager notificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    notificationManager.notify(0, notificationBuilder.build());
}
于 2015-11-26T12:09:58.757 回答
2

在您的活动节点中尝试 AndroidMenifest.xml 文件中的以下代码。

<activity name="SampleTabsDefault"
android:clearTaskOnLaunch="true"
android:finishOnTaskLaunch="true"
>
.....
</activity>

请在此处阅读这两个属性说明。

希望这能解决你的问题

于 2012-07-25T03:03:42.890 回答