9144

Notification restart my activity and pause button on notification

Question:

My notification get restart when i click on it by Status bar when i start my app it stream audio from server and show a notification until i don't clear it from status bar so my problem is when i click on my app notification it restart the activity and stop the streaming music.. so please suggests me solution for to stop restarting app again from notification and i want to show notification which stick on notification bar upto i exit from app Also I want to Show pause and Play button on Notification so please help me that too

public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); nm=(NotificationManager)getSystemService(NOTIFICATION_SERVICE); Intent intent = new Intent(this,MainActivity.class); PendingIntent pi= PendingIntent.getActivity(this, 0, in`enter code here`tent, 0); String body = " Welcome to streaming "; String title = "radio"; Notification n = new Notification(R.drawable.png, body, System.currentTimeMillis()); n.setLatestEventInfo(this , title, body, pi); n.defaults=Notification.DEFAULT_ALL; nm.notify(uniid,n);`

Answer1:

Add this in to your manifest file inside the activity which you are starting through notification, as if it is already running it won't be restarted again ..

android:launchMode="singleTop" android:configChanges="orientation|keyboardHidden" // fixes orientation

Don't allow to destroy your application on back press :

@Override public void onBackPressed() { moveTaskToBack(true); //super.onBackPressed(); // comment this line else your app will be destroyed }

Recommend

  • oracle query with several filter conditions
  • When a GitHub fork gets updated how do I keep my fork current while I still have a pending pull requ
  • Filtering rows by a particular index level in a MultiIndex dataframe
  • How should I handle multiple events per control w/command pattern using MVVM in Silverlight?
  • fixing ESPNConversations (add pause button)
  • Java - Pause initComponents from running?
  • WPF DispatcherFrame magic - how and why this works?
  • Handling interruptions in Sprite Kit - can't get sound effects via [SKAction playSoundFileNamed
  • Pausing and Playing SpriteKit Game in Swift
  • Updating Ui Components in Activity based on MediaPlayer object from Service While Playing music file
  • UIBarButton not changing
  • Javascript setTimeout works on desktop, not on android?
  • Check precision to nth decimal place?
  • Spinner in Chrome, IE9 does not become visible during synchronous ajax get request
  • Windows batch string manipulation in loop
  • Trouble downloading file from browser on Android
  • Reload UITableView from another tab
  • OnItemSelectedListener for Spinner that was added programmatically does not trigger
  • Replace Fragment with another on back button
  • Avoid registering duplicate broadcast receivers in Android
  • Why cout is producing no output on Code Blocks?
  • What is the difference between a “service account” and an “installed application”?
  • PushKit for VOIP iOS apps
  • How to get listview position?
  • Clear fused location provider's location for testing
  • Ubuntu and bcrypt
  • Why cepheus don't send int without quotes to orion?
  • Using JRuby with Rails 3.2
  • Code in Job's Script Block after Start-Process Does not Execute
  • Limiting recursion to certain level - Duplicate rows
  • Android fill_parent issue
  • Obtain ObjectIdHex value from mgo query
  • Adding custom controls to a full screen movie
  • jquery mobile loadPage not working
  • Properly structure and highlight a GtkPopoverMenu using PyGObject
  • How can I get HTML syntax highlighting in my editor for CakePHP?
  • EntityFramework adding new object to nested object collection
  • Checking variable from a different class in C#
  • failed to connect to specific WiFi in android programmatically
  • How can I use threading to 'tick' a timer to be accessed by other threads?