1

私のアプリは、ユーザーに通知する通知を作成します

アプリが 8 時間バックグラウンド プロセスにある場合

私が欲しいのは、通知を作成するプロセスを切り替えるだけです(バックグラウンド)

フォアグラウンドに、どうすればいいですか?

    // PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,
    // intent, PendingIntent.FLAG_CANCEL_CURRENT);

    NotificationManager manager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification;

    if (Build.VERSION.SDK_INT >= 16) {

        Notification.Builder builder = new Notification.Builder(this);
        builder.setContentIntent(pendingIntent);
        builder.setContentTitle(xx);
        builder.setContentText(xx);
        builder.setTicker(xx);
        builder.setLargeIcon(xx);
        builder.setSmallIcon(xx);
        builder.setDefaults(Notification.DEFAULT_ALL);
        notification = builder.build();

    } else {

        notification = new Notification(xx, xx, 0);
        notification.defaults |= Notification.DEFAULT_ALL;
        notification.setLatestEventInfo(this, xx, xx, pendingIntent);

    }

ここに画像の説明を入力

ここに画像の説明を入力

ありがとう

4

1 に答える 1

3

解決

    Intent intent = new Intent(this, StartWorkingActivity2.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);

これにより、実際に新しいアクティビティを作成することなく、既存のタスクが前面に表示されます。アプリケーションが実行されていない場合、アプリケーションは MyRootActivity のインスタンスを作成して開始します。

ユーザーがホームボタンをクリックした後にアプリケーションを前面に移動する

于 2013-02-12T07:03:42.333 に答える