为什么过了一会儿我的程序被强行关闭了?
Why After a while my program is force closed?
我的应用程序也可以运行,但是 12 或 24 小时后就无法运行,因为该程序已被操作系统关闭。
如何防止操作系统关闭程序?
我的phone模特:Huawei G620S-L02
我是这样设置闹钟的:
AlarmManager alarmManager = (AlarmManager) this.mContext.getSystemService(Context.ALARM_SERVICE);
Intent intentAlarm = new Intent(this.mContext, AlarmReciever.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this.mContext, 1, intentAlarm, PendingIntent.FLAG_UPDATE_CURRENT);
long time = System.currentTimeMillis() + 25 * 60 * 60 * 1000
alarmManager.set(AlarmManager.RTC_WAKEUP, time, pendingIntent);
这是AlarmReciever
:
public class AlarmReciever extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
PendingIntent pi = PendingIntent.getActivity(context,0,intent,PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
.setSmallIcon(R.mipmap.ic_launcher) // notification icon
.setTicker(sticker)
.setContentTitle("title") // title for notification
.setContentText("text) // message for notification
.setAutoCancel(true) // clear notification after click
.setContentIntent(pi)
.setLights(0xff00ff00, 300, 500)
.setShowWhen(false);
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(1, mBuilder.build());
}
}
我的 Manifest
是:
<receiver
android:name=".AlarmReciever"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE" />
</intent-filter>
在某些设备(如华为)中,您的应用必须在受保护的应用中进行检查:
转到设置 => 受保护的应用程序 => 检查你的应用程序
我的应用程序也可以运行,但是 12 或 24 小时后就无法运行,因为该程序已被操作系统关闭。
如何防止操作系统关闭程序?
我的phone模特:Huawei G620S-L02
我是这样设置闹钟的:
AlarmManager alarmManager = (AlarmManager) this.mContext.getSystemService(Context.ALARM_SERVICE);
Intent intentAlarm = new Intent(this.mContext, AlarmReciever.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this.mContext, 1, intentAlarm, PendingIntent.FLAG_UPDATE_CURRENT);
long time = System.currentTimeMillis() + 25 * 60 * 60 * 1000
alarmManager.set(AlarmManager.RTC_WAKEUP, time, pendingIntent);
这是AlarmReciever
:
public class AlarmReciever extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
PendingIntent pi = PendingIntent.getActivity(context,0,intent,PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
.setSmallIcon(R.mipmap.ic_launcher) // notification icon
.setTicker(sticker)
.setContentTitle("title") // title for notification
.setContentText("text) // message for notification
.setAutoCancel(true) // clear notification after click
.setContentIntent(pi)
.setLights(0xff00ff00, 300, 500)
.setShowWhen(false);
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(1, mBuilder.build());
}
}
我的 Manifest
是:
<receiver
android:name=".AlarmReciever"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE" />
</intent-filter>
在某些设备(如华为)中,您的应用必须在受保护的应用中进行检查:
转到设置 => 受保护的应用程序 => 检查你的应用程序