删除通知栏时,应用程序是通过刷卡的动作关闭 [英] Removing notification bar when the application is closed through swipe action

查看:114
本文介绍了删除通知栏时,应用程序是通过刷卡的动作关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我打开应用程序,我preSS home键,它仍然在后台播放(它显示与播放和停止的通知吧),过了一会儿,我希望它关闭它,所以我很pressing home键,直到它显示我的活动应用程序,然后轻扫它关闭,所以如果我关闭它这样我想我的应用程序消失通知

When i open the app, i press the home button and it still plays in background (it shows a notification bar with play and stop), after a while i want it to close it so i'm pressing home button until it shows me the active applications and then swipe it to close, so if i close it like this i want the notification for my app to disappear

如何删除通过活动应用程序的列表,如果它与刷卡动作关闭是相关的应用程序我的通知栏时,守pressing家(当你在设备的主屏幕)?

How can i remove my notification bar that is related to the application if it's closed with the swipe action through the 'list of active applications when keep pressing home (when you are in the home screen of the device) ?

**实现了从班里的onDestroy()方法时,我刷卡关闭该应用程序是不是叫

** Realized the onDestroy() method from my class isn't called when i swipe to close the application

**第二意识到我必须调用服务,以获得对onTaskRemoved(),以在这个方法我可以实现notificationManager关闭

** Second realize that i have to call the Service in order to get to the onTaskRemoved() to which in this method i can implement the notificationManager to close

推荐答案

好了,我已经想通了。

Ok, so i have figured it out.

首先,我会做一个服务类

First i will make a Service Class

public class MyService extends Service {

@Override
public void onCreate()
{   
    super.onCreate();
}

@Override
public IBinder onBind(Intent intent) {
    // TODO Auto-generated method stub
    return null;
}

}

现在我要去的的onPause()

now Im going to start the service in the onPause()

  startService(new Intent(this, MyService.class));

和则的onDestroy()方法(它被称为与服务的帮助下)

and then the onDestroy() method (it is called with the help of Service)

@Override
protected void onDestroy()
{           
    super.onDestroy();              

    String ns = Context.NOTIFICATION_SERVICE;
    NotificationManager nMgr = (NotificationManager) this.getSystemService(ns);
    nMgr.cancel(1);     
}   

和别忘了在清单中添加

 <service android:name="this.MyPackage.MyService" 
             android:stopWithTask="false"   >            
    </service>
 </application>

这篇关于删除通知栏时,应用程序是通过刷卡的动作关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆