It would be reasonable to start a service when the device is idle.
I think it would be unreasonable to start a visible activity without
user interaction. The user will start your app when they want to.

On Jul 27, 3:47 am, optimusgeek <[email protected]> wrote:
> 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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to