【发布时间】:2016-02-12 13:04:04
【问题描述】:
我的应用程序也可以运行,但 12 或 24 小时后无法运行,因为该程序已被操作系统关闭。
如何防止操作系统关闭程序?
我的手机型号: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>
【问题讨论】:
-
简短回答你不能。尝试使用 AlarmManager、BroadcastReceiver 和 Services
-
@RaduIonescu 我使用的是 AlarmManager、BroadcastReceiver、Services 和你想的一切!但是当我的应用程序强制关闭时,不工作!。我的应用程序运行良好但 12 或 24 小时后不起作用,因为该程序已被操作系统关闭。
-
您应该在您的帖子中包含此信息。添加更多有关您正在使用的内容的详细信息,并可能添加有关如何管理剩余部分的代码
-
请指导我,而不是投反对票。
-
我没有对你投反对票,我正在努力帮助你:)
标签: android forceclose reminders