2011-07-04 18 views
16

मेरे पास एक ऐसा एप्लिकेशन है जो किसी सेवा की सहायता से मीडिया चलाता है। यह एक सेवा की मदद से आसानी से चलता है (चल रही अधिसूचना बनाई गई है)। जब बैक कुंजी दबाया जाता है तो एप्लिकेशन पृष्ठभूमि में जाता है। समस्या यह है कि जब मैं अधिसूचना आइकन पर क्लिक करता हूं तो मेरे आवेदन का एक नया उदाहरण हर बार बनाया जाता है। अधिसूचना बार की मदद से मैं पृष्ठभूमि से आगे तक अपना आवेदन कैसे प्राप्त कर सकता हूं?जब अधिसूचना आइकन क्लिक किया जाता है (सेवा से) पर एप्लिकेशन को सामने कैसे लाया जाए?

private void notifyMe() { 
    final NotificationManager mgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); 
    Notification note = new Notification(R.drawable.icon_audio, "Online!", 
      System.currentTimeMillis()); 
    note.flags = Notification.FLAG_ONGOING_EVENT; 
    PendingIntent i = PendingIntent.getActivity(this, 0, new Intent(this, PlayMedia.class), 0); 
    note.setLatestEventInfo(this, "Media Payer", "Online",i); 
    mgr.notify(NOTIFY_ME_ID, note); 
} 

समाधान मैं इसे मैनिफ़ेस्ट फ़ाइल में निम्न पंक्ति जोड़कर काम मिल गया: एंड्रॉयड: launchMode = "singleInstance" आशय झंडा नहीं था '

मेरी सूचना इस तरह दिखता है टी का कोई असर नहीं है, सोचा था कि अजीब था ...

उत्तर

3

आप जिस उद्देश्य को लंबित INTent.getActivity पर पास करते हैं, उसके सामने एक चल रहे एप्लिकेशन को सामने लाने के लिए उचित ध्वज सेट होना आवश्यक है। तो:

Intent startActivity = new Intent(this,PlayMedia.class); 
startActivity.setFlags(Intent.*appropriate flag*); 
PendingIntent i = PendingIntent.getActivity(this, 0, startActivity, 0); 

करने के लिए http://developer.android.com/reference/android/content/Intent.html और खोज (Ctrl + F) के लिए "flag_" जाओ। वहां आप उन झंडे की एक सूची पाएंगे जिनका आप उपयोग कर सकते हैं।

+17

इस प्रश्न को पढ़ने वाले लोगों के लिए + उत्तर, हालांकि पूछने वाले ने इस उत्तर को सर्वश्रेष्ठ के रूप में स्वीकार किया, यह समाधान नहीं है जिसने अपनी समस्या हल की है। सही समाधान के लिए, – Marmoy

+0

प्रश्न के अंतिम भाग को पढ़ें यदि वह कहता है कि आपने XML में कहां रखा है या xml कोड दिखाया है तो अच्छा होगा। – JPM

+0

जहां तक ​​मुझे याद है कि आपने लॉन्चमोड को अभिव्यक्ति में गतिविधि तत्व (ओं) में एक विशेषता के रूप में सेट किया है, जिसे आप लॉन्च व्यवहार को बदलना चाहते हैं। – Marmoy

3

उत्तर पर सिर्फ एक भिन्नता और प्रश्न पर एक टिप्पणी। मुझे एंड्रॉइड जोड़ने की ज़रूरत नहीं थी: लॉन्चमोड = "सिंगल इंस्टेंस" अल्पर के रूप में सुझाव देता है। एक ऐसा ऐप है जो मैंने एप को अग्रभूमि में लाने के लिए किया था।

// this code brings the application from background to foreground 
// when the Notification icon is clicked on. 

// create new notification 
int icon = R.drawable.ic_notify; 
Notification notification = new Notification(icon, "Ticker Text", System.currentTimeMillis()); 

// Create new Intent pointing to activity you want it to come back to 
Intent notificationIntent = new Intent(this, MainApp.class); 

// Add new intent to a pending intent 
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); 

// add that pendingIntent to the new notification 
notification.setLatestEventInfo(getApplicationContext(), "Title", "Text", contentIntent); 

// send the intent to the NotificationManager 
((NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE)).notify(UPLOADER_ID, notification); 
1

सभी इस Android 5 में अब और काम नहीं करता है मैं सभी उपरोक्त सुझावों की कोशिश की और मेरे ऐप को नष्ट कर दिया और पुन: प्रारंभ जब भी मैं अधिसूचना क्लिक किया हो रही रखा।

Intent resultIntent = new Intent(context, MainActivity.class); 
resultIntent.setAction(Intent.ACTION_MAIN); 
resultIntent.addCategory(Intent.CATEGORY_LAUNCHER); 
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, resultIntent, 0); 

यह है कि यह सभी एप्लिकेशन स्क्रीन पर टैप किया गया था अपने अनुप्रयोग वापस सामने लाने के लिए होगा:

इसे ठीक करने के लिए, सब मुझे क्या करना जरूरत आशय के लिए 2 झंडे जोड़ने था।

+0

एंड्रॉइड के साथ संयोजन में मेरे लिए काम किया: launchMode = "सिंगल टास्क" तो +1 क्योंकि सभी अन्य नहीं –

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