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
この回答を実行し、コマンドを使用して、サービスがフォアグラウンドで正しく実行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);
}
通知アイコン: ( 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);
}