通知重启我的活动并暂停通知按钮

时间:2012-08-29 09:02:34

标签: android statusbar notificationmanager

当我按状态栏点击时,我的通知会重新启动 当我启动我的应用程序时它从服务器传输音频并显示通知,直到我不从状态栏清除它所以我的问题是当我点击我的应用程序通知它重新启动活动并停止流媒体音乐.. 所以请建议我从通知再次停止重新启动应用程序的解决方案,我想显示通知栏上的通知我从app退出 此外,我想在通知上显示暂停和播放按钮,所以请帮助我

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 个答案:

答案 0 :(得分:1)

将此添加到您通过通知启动的活动内的清单文件中,就好像它已经在运行它不会再次重新启动..

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

请勿在背面按下时销毁您的应用程序:

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

}