问题
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);`
回答1:
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
}
来源:https://stackoverflow.com/questions/12174279/notification-restart-my-activity-and-pause-button-on-notification