0
我的應用程序也可以工作,但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和服務 –
@RaduIonescu我用AlarmManager,BroadcastReceiver,服務和你認爲的一切!,但是當我的應用程序強制關閉,沒有工作!。我的應用程序perfectlly工作但12或24小時後無法正常工作因爲該程序已被操作系統關閉。 – javadaskari
然後,您應該在您的帖子中包含這些信息。添加一些你正在使用的細節,也許代碼如何管理這個剩餘部分 –