“之后的Android通知”;“所有应用程序关闭”;按钮

“之后的Android通知”;“所有应用程序关闭”;按钮,android,notifications,alarmmanager,Android,Notifications,Alarmmanager,我在我的应用程序中使用了通知,一切都很好——通知在我想要的时间显示,即使在设备重新启动之后 但是,当我单击“特殊”按钮关闭所有应用程序时,它会关闭我的应用程序,通知根本不会显示 “关闭所有应用程序的特殊按钮”-我指的是一个可以列出所有后台应用程序,然后单击“全部杀死”的按钮 我正在OnePlus 3T上测试一切 单击“杀死所有应用”后是否可以再次运行该服务 舱单: <uses-permission android:name="android.permission.WAKE_LOCK

我在我的应用程序中使用了通知,一切都很好——通知在我想要的时间显示,即使在设备重新启动之后

但是,当我单击“特殊”按钮关闭所有应用程序时,它会关闭我的应用程序,通知根本不会显示

“关闭所有应用程序的特殊按钮”-我指的是一个可以列出所有后台应用程序,然后单击“全部杀死”的按钮

我正在OnePlus 3T上测试一切

单击“杀死所有应用”后是否可以再次运行该服务

舱单:

    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

    ...

        <receiver
            android:name="com.saga.thewitcherquotes.QuoteOfTheDayReceiver"
            android:enabled="true"
            android:exported="false" >
        </receiver>

        <receiver android:name="com.saga.thewitcherquotes.DeviceBootReceiver"
            android:enabled="true"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
            </intent-filter>
        </receiver>

        <service
            android:name="com.saga.thewitcherquotes.QuoteOfTheDayIntentService"
            android:exported="false"></service>
具有通知生成器的服务:

public class QuoteOfTheDayIntentService extends IntentService {
    private static final int NOTIFICATION_ID = 3;


    public QuoteOfTheDayIntentService() {
        super("MyNewIntentService");
    }

    @Override
    protected void onHandleIntent(Intent intent) {
        Notification.Builder builder = new Notification.Builder(this);
        builder.setContentTitle(getString(R.string.quote_of_the_day));
        DatabaseHandler db = DatabaseHandler.getInstance(this);
        Random generator = new Random();
        int id = generator.nextInt(db.getQuotesSize());
        Quote quote = db.getQuote(id, null);
        builder.setContentText(quote.getQuote());
        builder.setSmallIcon(R.drawable.swords);
        builder.setAutoCancel(true);
        Intent notifyIntent = new Intent(this, MainActivity.class);
        notifyIntent.putExtra("id",id-1);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        builder.setContentIntent(pendingIntent);
        Notification notificationCompat = builder.build();
        NotificationManagerCompat managerCompat = NotificationManagerCompat.from(this);
        managerCompat.notify(NOTIFICATION_ID, notificationCompat);
    }
}

您的通知生成器在哪里?您使用的是哪种类型的服务?服务还是意向服务???意向服务,很抱歉我之前忘记添加。
public class QuoteOfTheDayIntentService extends IntentService {
    private static final int NOTIFICATION_ID = 3;


    public QuoteOfTheDayIntentService() {
        super("MyNewIntentService");
    }

    @Override
    protected void onHandleIntent(Intent intent) {
        Notification.Builder builder = new Notification.Builder(this);
        builder.setContentTitle(getString(R.string.quote_of_the_day));
        DatabaseHandler db = DatabaseHandler.getInstance(this);
        Random generator = new Random();
        int id = generator.nextInt(db.getQuotesSize());
        Quote quote = db.getQuote(id, null);
        builder.setContentText(quote.getQuote());
        builder.setSmallIcon(R.drawable.swords);
        builder.setAutoCancel(true);
        Intent notifyIntent = new Intent(this, MainActivity.class);
        notifyIntent.putExtra("id",id-1);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        builder.setContentIntent(pendingIntent);
        Notification notificationCompat = builder.build();
        NotificationManagerCompat managerCompat = NotificationManagerCompat.from(this);
        managerCompat.notify(NOTIFICATION_ID, notificationCompat);
    }
}