在Android 4.4.2中,單擊我的前臺服務通知正在終止我的進程。前臺服務正在通知中點擊
在較舊的設備上(Samsuing Tab 2運行4.2.2),我可以從最近的任務中刪除活動,並且仍然可以在後臺運行我的Service
。然後當我點擊Notification
我的應用程序Activity
再次開始相當愉快。
但是,一旦我點擊運行4.4.2的Nexus 7上的通知,我的進程就會被終止(直到點擊在後臺運行愉快)。該PendingIntent
似乎並沒有在各消防,或至少,它沒有擊中BroadcastReceiver
的第一行:
05-21 16:17:38.939: I/ActivityManager(522): Killing 2268:com.test.student/u0a242 (adj 0): remove task
我已經通過this答案運行,並且使用命令dumpsys activity proccesses
我已經確認我的服務是正確運行在前臺。
那麼,點擊這個通知會導致我的進程被終止是什麼?參與移動服務的前景
代碼如下:
服務:
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.i("NativeWrappingService", "Starting Service...");
startForeground(NotificationIcon.NOTIFICATION_STUDENT, NotificationManager.getStudentIcon(this).getNotification());
return super.onStartCommand(intent, flags, startId);
}
NotificationIcon:(getStudentIcon(this).getNotification()
)
public Notification getNotification() {
Builder mBuilder = new Builder(mContext);
if(mSmallIcon != -1) mBuilder.setSmallIcon(mSmallIcon);
if(mLargeIcon != null) mBuilder.setLargeIcon(mLargeIcon);
if(mTitle != null) mBuilder.setContentTitle(mTitle);
if(mSubTitle != null) mBuilder.setContentText(mSubTitle);
if(mSubTitleExtra != null) mBuilder.setContentInfo(mSubTitleExtra);
mBuilder.setOngoing(mOngoing);
mBuilder.setAutoCancel(mAutoCancel);
mBuilder.setContentIntent(getPendingIntent(mContext, mAction, mBundle, mActivity));
return mBuilder.build();
}
private PendingIntent getPendingIntent(Context context, String action, Bundle extras, String activity) {
Intent newIntent = new Intent(context, BroadcastToOrderedBroadcast.class);
Bundle bundle;
if(extras != null) bundle = extras;
else bundle = new Bundle();
if(activity != null && !activity.equalsIgnoreCase("")) {
BundleUtils.addActivityToBundle(bundle, activity);
}
BundleUtils.addActionToBundle(bundle, action);
newIntent.putExtras(bundle);
return PendingIntent.getBroadcast(NativeService.getInstance(), mNotificationID, newIntent, PendingIntent.FLAG_UPDATE_CURRENT);
}
這是一個已知的錯誤,正在跟蹤[這裏](https://code.google.com/p/android/issues/detail?id=53313)。您可以嘗試[comment#7](https://code.google.com/p/android/issues/detail?id=53313#c7)中列出的解決方案。 –