从任务管理器中终止应用程序后重新启动服务

时间:2014-06-28 10:21:09

标签: android service

我开始这样的服务

Intent service1 = new Intent(context,MyService.class);                         service1.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);

context.startService(服务1);

这是我在服务类

中的onstart
public void onStart(Intent intent, int startid) {
        player.start();
        this.getApplicationContext();
        mManager = (NotificationManager) this.getApplicationContext()
                .getSystemService(Context.NOTIFICATION_SERVICE);
        Intent intent1 = new Intent(this.getApplicationContext(), Alarm.class);

        Notification notification = new Notification(R.drawable.icon,
                "Phone start ringing!", System.currentTimeMillis());

        intent1.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP
                | Intent.FLAG_ACTIVITY_CLEAR_TOP);

        PendingIntent pendingNotificationIntent = PendingIntent.getActivity(
                this.getApplicationContext(), 0, intent1,
                PendingIntent.FLAG_UPDATE_CURRENT);
        notification.flags |= Notification.FLAG_HIGH_PRIORITY;

        notification.setLatestEventInfo(this.getApplicationContext(),
                "Ping My Android", "Confirm Your identity!",
                pendingNotificationIntent);

        mManager.notify(125, notification);

这是清单

<service
        android:name=".MyService"
        android:enabled="true" />

问题是当我从任务管理器中删除我的应用程序时,服务需要2到3秒,然后重新启动,我的警报从启动开始重启。

0 个答案:

没有答案
相关问题