• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Recent Apps (Home button long press)

Experienced developers: is there a way built in to the SDK to hook and replace the home button long press recent apps feature? I am thinking about writing a more useful recent apps screen, potentially including favorite apps, etc.
 
That would be very, very nice.

Be sure to include "Top-5 apps" by most-time-active as well as most-often-launched ! :)
I did this for my Palm, and it was bloody brilliant; a self-optimising "start menu".
 
Interesting suggestion. Right now though what I'm really trying to figure out is whether this is technically possible within the API
 
Try looking into android.view.KeyEvent and public static final int KEYCODE_HOME ... ? I haven't tried this in Android, but it looks like you can hook into the hardware buttons; although I'm not sure if your app needs to have focus in order to do that.

Things sure were simpler when I was programming for a certain defunct event-driven OS. :rolleyes:
 
Try looking into android.view.KeyEvent and public static final int KEYCODE_HOME ... ? I haven't tried this in Android, but it looks like you can hook into the hardware buttons; although I'm not sure if your app needs to have focus in order to do that.

Things sure were simpler when I was programming for a certain defunct event-driven OS. :rolleyes:

Based on my research, it looks like, yes, my app would have to be in the foreground to use that method. But I can possibly trigger from a short press of the camera button instead, which shouldn't be too disruptive, since the camera is launched with a long press of the button.

But the next obstacle is what app statistics are available through the API?


  • Can I get a recent apps list, running times, and launch counts from the API?
  • If not, can any of these things be monitored from a service?
  • Is there an event that triggers when any new app is launched, which I could handle?
  • Is there an event that triggers when any app is closed?
 
All those questions you have, I could answer ... for PalmOS. :o For Android, I'll just sit here quietly and hope somebody else comes by.
 
  • Can I get a recent apps list, running times, and launch counts from the API?
ActivityManager's getRunningTasks should help. Running has a different meaning in Android than in the rest of the world, so this really means recent. I don't think the api includes statistics, but the PackageManager API is what to look into for that
  • If not, can any of these things be monitored from a service?
yes
  • Is there an event that triggers when any new app is launched, which I could handle?
There's the accessibility API which lets you actually get an event for this, or you can read the system log and look for the Starting activity string.

  • Is there an event that triggers when any app is closed?

I believe the accesibility API will help again for that. Maybe the ActivityManager puts something in the log, but that depends on how it's "closed".
 
... somebody else comes by and ... ;D

As far as "what app statistics are available through the API?" goes, perhaps you are looking for:

Code:
ActivityManager am = (ActivityManager)this.getSystemService(ACTIVITY_SERVICE);
List<ActivityManager.RunningAppProcessInfo> apps = am.getRunningAppProcesses();
List<ActivityManager.RecentTaskInfo> tasks = am.getRecentTasks(20,
 ActivityManager.RECENT_WITH_EXCLUDED); // requires GET_TASKS perms!

and relatives?

Interested in discussing possible apps?
 
A press of the HOME key cannot be "caught" so to speak, but you cna still do what you are trying to do... Because of how the lifecycle works, when the user presses the home key, he/she should be taken to his/her 'safe place'. You can define your activiy as one of these 'safe places' by adding the following intent-filter:

Code:
<intent-filter>
     <action android:name="android.intent.action.MAIN" />
     <category android:name="android.intent.category.HOME" />
     <category android:name="android.intent.category.DEFAULT" />
</intent-filter>

Each time the home key is pressed, the activity that contains the aforementioned filter will be launched by call of the onNewIntent() method. You can override this method and implement any functionality you wish.
 
Back
Top Bottom