List of all of the activities in our application that are running on the device

眉间皱痕 提交于 2019-11-30 08:46:25
TopherC

I've found AppLifecycleHandler as documented in this post to be a great solution for knowing what's happening. I use it primarily to just keep count and clean up when the user is done using the app, but you can implement it with an array in which you store all running activities so you can always call in to find out what's running.

This is the way to get all the running activities in the application -

try {
    ActivityInfo[] list = getPackageManager().getPackageInfo(getPackageName(),PackageManager.GET_ACTIVITIES).activities;

        for(int i = 0;i< list.length;i++)
        {
            System.out.println("List of running activities"+list[i].name);

        } 
    }

    catch (NameNotFoundException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!