Trong Android 4.4.2, nhấp vào thông báo Dịch vụ Foreground của tôi đang giết chết quá trình của tôi.Dịch vụ Foreground bị giết khi nhấp vào Thông báo
Trên các thiết bị cũ hơn (Samsuing Tab 2 chạy 4.2.2), tôi có thể vuốt hoạt động từ các tác vụ gần đây và vẫn còn hoạt động Service
hoạt động tốt trong nền. Sau đó, khi tôi nhấp vào Notification
, ứng dụng Activity
của tôi sẽ bắt đầu lại khá vui vẻ.
Tuy nhiên, khi tôi nhấp vào Thông báo trên Nexus 7 của tôi đang chạy 4.4.2, quá trình của tôi sẽ bị xóa (cho đến khi nhấp chuột đang chạy một cách vui vẻ trong nền). Các PendingIntent
dường như không bắn ở tất cả, hoặc ít nhất, nó không nhấn dòng đầu tiên của BroadcastReceiver
:
05-21 16:17:38.939: I/ActivityManager(522): Killing 2268:com.test.student/u0a242 (adj 0): remove task
tôi đã chạy qua this câu trả lời, và sử dụng lệnh dumpsys activity proccesses
Tôi đã đã xác nhận rằng Dịch vụ của tôi là chạy ở mặt nền chính xác.
Vì vậy, điều gì xảy ra khi nhấp vào Thông báo này đang giết quá trình của tôi?
Mã tham gia trong việc di chuyển Dịch vụ cho Foreground sau:
dịch vụ:
@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);
}
Đó là lỗi đã biết đang được theo dõi [tại đây] (https://code.google.com/p/android/issues/detail?id=53313). Bạn có thể thử giải pháp được liệt kê trong [comment # 7] không (https://code.google.com/p/android/issues/detail?id=53313#c7). –