I want to start my activity when the device is in idle(home screen).
I found a solution like below.

=================================================
ActivityManager actvityManager =
    (ActivityManager)getSystemService( ACTIVITY_SERVICE );
List<ActivityManager.RunningTaskInfo> task =
    actvityManager.getRunningTasks(1);
ComponentName topActivity = task.get(0).topActivity;
String strPackage = topActivity.getPackageName();

PackageManager pm = getPackageManager();
Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_HOME);
List<ResolveInfo> mApps;
mApps = pm.queryIntentActivities(mainIntent, 0);

int count = mApps.size();

for(int i=0; i<count; i++){
    ResolveInfo info = mApps.get(i);
    ActivityInfo activity = info.activityInfo;
    if(activity.packageName.equals(strPackage))
    {
        return true;
    }
}
return false;
===============================================

Is that reasonable?? I'm not sure there is more good solution.
please give me any opinion.
thank you.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to