检查我的应用程序在运行Android [英] Check if my App is running in Android
问题描述
我有涉及声音池中的应用程序 - 在应用程序启动所有的声音都是其主屏幕加载后加载
I have an application which involves sound pool - On start of the application all the sounds are loaded after which main screen is loaded.
现在,我想检查应用程序运行 - 如果不跑,我想重新加载应用程序 - 如果正在运行,我不想重装应用程序
Now, I would like to check if the application is running - if is not running I would like to reload the application - if it is running I don't want reload the application.
对于我试过如下:
ActivityManager activityManager = (ActivityManager) this.getSystemService( ACTIVITY_SERVICE );
List<RunningAppProcessInfo> procInfos = activityManager.getRunningAppProcesses();
for(int i = 0; i < procInfos.size(); i++){
if(procInfos.get(i).processName.equals("com.me.checkprocess"))
{
Log.e("Result", "App is running - Doesn't need to reload");
}
else
{
Log.e("Result", "App is not running - Needs to reload);
}
}
这给出了结果很完美,但是,一直检查到procInfos.size较小的0。在应用过程中得到真正的com.me.checkprocess - 它总是假的?所以它总是进入else部分第一。
This gives the results out perfectly but keeps on checking until procInfos.size is lesser that 0. Until the app gets process com.me.checkprocess true - it is always false? so it always gets into the else part first.
因此,例如:如果总过程为30。而我的过程com.me.checkprocess运行@ 29位。当执行条件。直到28日过程中,它是和别的@ 29日过程中,它进入的条件真。
So for example: If the total process is 30. And my process com.me.checkprocess is running @29th. When execute the condition. Until 28th process it is else and @29th process it gets into the condition true.
如何解决这部分 - 我想获得总过程只检查后else部分
How to fix this part - I would like to get to else part only after total process is checked?
让我知道!
推荐答案
我觉得你可以再补充
break;
在
Log.e("Result", "App is running - Doesn't need to reload");
在如果
语句
这篇关于检查我的应用程序在运行Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!