在刷卡一条龙服务,删除 [英] Stop service on swipe to remove

查看:200
本文介绍了在刷卡一条龙服务,删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

应用从最近打开的应用程序列表中轻扫杀死。

在我的应用程序,
结果我的运行服务在后台只有当应用程序在前台提供背景。如果用户的在后台发送应用程序通过移动然后服务也应该运行的pressing home键

结果但是,当用户的删除应用程序最近打开的应用程序,然后
结果1)是否有任何方法自动调用最近的应用程序列表中删除的时候?
结果2)哪种方法会调用?


  • 我的要求:
    结果,当应用程序会从最近打开的应用程序在那个时候删除我会
    一站式服务这backgound已经运行。结果
    结果

    • 面对问题:
      结果1)我有活动,N多...
      结果2)我也想知道你,当应用程序将最近列表中删除。 Android操作系统不叫的onDestroy()方法均匀。活动是在活动堆栈。



解决方案

 公共布尔isAppRunning()
    {
        布尔appFound = FALSE;
        最后ActivityManager activityManager =(ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);
        最终名单< RunningTaskInfo> recentTasks = activityManager.getRunningTasks(Integer.MAX_VALUE的);        对于(RunningTaskInfo recentTask:recentTasks)
        {            如果(recentTask.baseActivity.getPackageName()。等于(your.packagename))
            {
                appFound = TRUE;
                打破;
            }        }
        返回appFound;
    }

用这个方法我已经解决了我的问题,如果我有错误的话,我会关闭我的服务。

需要添加权限:搜索

 <使用许可权的android:NAME =android.permission.GET_TASKS/>

希望它的方法加工的。

App killed from Recently open application list by swipe.

In my application,
I am running service in background only when application is available in foreground or in background. If user has sent application in background by pressing home button of mobile then also service should be run.


But when user remove application from recently opened application then
1) Is any methods invoke automatically when removed from recent app list?
2) Which method will be invoke?

  • My Requirement:
    when application going to remove from recently open application at that time i will stop service which is already running in backgound.

    • Issue Faced:
      1) I have N number of activities...
      2) I also want to know you that when application going to remove from recent list. Android OS not called onDestroy() method even . Activities which is in activity stack.

解决方案

public boolean isAppRunning()
    {
        boolean appFound = false;
        final ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        final List<RunningTaskInfo> recentTasks = activityManager.getRunningTasks(Integer.MAX_VALUE);

        for (RunningTaskInfo recentTask : recentTasks)
        {

            if (recentTask.baseActivity.getPackageName().equals("your.packagename"))
            {
                appFound = true;
                break;
            }

        }
        return appFound;
    }

using this method i have solved my problem if i got false then i will close my service.

need to add permission:

<uses-permission android:name="android.permission.GET_TASKS" />

Hope its worked

这篇关于在刷卡一条龙服务,删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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