通知重新启动我的活动,并在暂停通知按钮 [英] Notification restart my activity and pause button on notification
问题描述
我通知的方式重启,当我点击它通过状态栏
当我开始我的应用程序流式传输来自服务器的音频和显示通知,直到我并不清楚它的状态栏,所以我的问题是,当我在我的应用程序的通知点击它重新启动活动,并停止流媒体音乐..
所以请建议我停止从通知再次重新启动应用程序解决方案,我想显示其通知贴通知栏上从高达应用程序我退出
此外,我想表明暂停和播放的通知按钮,请帮助我,太
公共无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState); 的setContentView(R.layout.activity_main); 纳米=(NotificationManager)getSystemService(NOTIFICATION_SERVICE); 意向意图=新意图(这一点,MainActivity.class);
PI的PendingIntent = PendingIntent.getActivity(这一点,0,in`enter code here`tent,0);
绳体=欢迎来到流;
字符串title =无线电;
通知N =新的通知(R.drawable.png,身体,System.currentTimeMillis的());
n.setLatestEventInfo(这一点,标题,正文,PI);
n.defaults = Notification.DEFAULT_ALL;
nm.notify(uniid,N);`
在添加这您是通过通知启动里面的活动清单文件,就好像它已经在运行它不会被再次重新启动..
的android:launchMode =singleTop
机器人:configChanges =方向| keyboardHidden//修正方向
不允许破坏你的背部preSS应用程序:
@覆盖
公共无效onBack pressed()
{
moveTaskToBack(真);
//super.onBack$p$pssed(); //注释此行还有你的应用程序将被销毁}
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);`
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
}
这篇关于通知重新启动我的活动,并在暂停通知按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!