출처 : http://kpbird.blogspot.com/2011/08/android-check-application-is-running.html
Android: Check application is running ?
Wednesday, August 17, 2011
| Android has different application lifecycle, Many times user press Home hardware button and application goes in background, Application is still running but it's in background, Now We want to identify that application is running in background or not. It require when we don't want to create new instance of Activity. Android SDK provide class named ActivityManager. Using ActivityManager we can check application is running in background.
Here is the simple code for the same. you just need to change package name as per your requirement.
Reference:
http://developer.android.com/reference/android/app/ActivityManager.html
Here is the simple code for the same. you just need to change package name as per your requirement.
01 |
ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE); |
02 |
// get the info from the currently running task |
03 |
List < ActivityManager.RunningTaskInfo > taskInfo = am.getRunningTasks( 1 ); |
04 |
|
05 |
Log.d( "current task :" , "CURRENT Activity ::" + taskInfo.get( 0 ).topActivity.getClass().getSimpleName()); |
06 |
|
07 |
ComponentName componentInfo = taskInfo.get( 0 ).topActivity; |
08 |
//if app is running |
09 |
if (componentInfo.getPackageName().equalsIgnoreCase(*Package Name*)) |
10 |
{ |
11 |
//do the implementation for if your app is running |
12 |
} |
Reference:
http://developer.android.com/reference/android/app/ActivityManager.html
'Android > Tip&Tech' 카테고리의 다른 글
[펌]안드로이드 아이폰 스타일 on/off 만들기 (0) | 2011.09.26 |
---|---|
android 해상도 및 가로/세로 알아내기 (1) | 2011.09.26 |
[팁]자바상에서 text 가변크기 설정(sp,dp등등) (0) | 2011.09.21 |
c2dm php 팁#1 (3) | 2011.09.21 |
크롬용 웹 개발툴 설치 주소. (0) | 2011.09.20 |