5

मेरी अग्रभूमि सेवा अधिसूचना पर एंड्रॉयड 4.4.2 क्लिक में मेरी प्रक्रिया मार रहा है पर मार डाला जा रहा है।अग्रभूमि सेवा अधिसूचना क्लिक

पुराने उपकरणों (सैमसंग टैब 2 4.2.2 चल रहा है) पर, मैं हालिया कार्यों से गतिविधि को स्वाइप कर सकता हूं और अभी भी पृष्ठभूमि में ठीक चल रहा है Service। फिर जब मैं फिर से काफी खुशी से Notification मेरे ऐप Activity शुरू होता है पर क्लिक करें।

हालांकि, एक बार मैं अधिसूचना मेरी नेक्सस 7 चल रहा है 4.4.2 मेरी प्रक्रिया मार दिया जाता है (जो जब तक क्लिक पृष्ठभूमि में खुशी से चल रहा है) पर क्लिक करें। PendingIntent बिल्कुल आग नहीं लगती, या कम से कम, यह BroadcastReceiver की पहली पंक्ति हिट नहीं करता:

05-21 16:17:38.939: I/ActivityManager(522): Killing 2268:com.test.student/u0a242 (adj 0): remove task 

मैं आदेश dumpsys activity proccesses मैंने का उपयोग कर this जवाब के माध्यम से चलाने की है, और पुष्टि की है कि मेरी सेवा है अग्रभूमि में सही ढंग से चल रहा है।

तो, क्या यह इस अधिसूचना जो मेरे प्रक्रिया मार रहा है पर क्लिक बारे में है?

कोड अग्रभूमि करने के लिए सेवा चलती में शामिल इस प्रकार है:

सेवा:

@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); 
} 
+0

यह एक ज्ञात बग है जिसे ट्रैक किया जा रहा है [यहां] (https://code.google.com/p/android/issues/detail?id=53313)। आप समाधान में [टिप्पणी 7 #] सूचीबद्ध (https://code.google.com/p/android/issues/detail?id=53313#c7) की कोशिश कर सकते हैं। –

उत्तर

4

को PendingIntent अपनी अधिसूचना से इस्तेमाल किया FLAG_RECEIVER_FOREGROUND झंडा जोड़े सेवा को अग्रभूमि प्राथमिकता पर चलाने की अनुमति देने के लिए।

Intent newIntent = new Intent(context, BroadcastToOrderedBroadcast.class); 
newIntent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); 
return PendingIntent.getBroadcast(NativeService.getInstance(), mNotificationID, newIntent, PendingIntent.FLAG_UPDATE_CURRENT); 

यहां इस जानकारी का स्रोत है: Android Issue Tracker tool

+0

क्या यह FLAG_ACTIVITY_NEW_TASK के समतुल्य नहीं है? वे दोनों 0x10000000 हैं, क्या आप संदर्भ का समर्थन कर सकते हैं कि मैं FLAG_RECEIVER_FOREGROUND को सेट कर सकता हूं? –

+0

@ मुलिमानी याद रखें मैं आपके सुझाव के माध्यम से चला गया। जब मेरा ऐप बंद हो जाता है और यदि मैं अधिसूचना पर क्लिक करता हूं तो मेरी सेवा पुनरारंभ हो रही है। और ब्रॉडकास्ट रिसीवर भी काम नहीं कर रहा है? –

संबंधित मुद्दे