Recent Apps (Home button long press)


Last Updated:

  1. acjohnson55

    acjohnson55 Active Member This Topic's Starter

    Joined:
    Dec 6, 2009
    Messages:
    30
    Likes Received:
    3
    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.
     

    Advertisement
  2. KlaymenDK

    KlaymenDK Well-Known Member

    Joined:
    May 29, 2009
    Messages:
    1,217
    Likes Received:
    130
    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".
     
  3. acjohnson55

    acjohnson55 Active Member This Topic's Starter

    Joined:
    Dec 6, 2009
    Messages:
    30
    Likes Received:
    3
    Interesting suggestion. Right now though what I'm really trying to figure out is whether this is technically possible within the API
     
  4. KlaymenDK

    KlaymenDK Well-Known Member

    Joined:
    May 29, 2009
    Messages:
    1,217
    Likes Received:
    130
    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:
     
  5. acjohnson55

    acjohnson55 Active Member This Topic's Starter

    Joined:
    Dec 6, 2009
    Messages:
    30
    Likes Received:
    3
    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?
     
  6. KlaymenDK

    KlaymenDK Well-Known Member

    Joined:
    May 29, 2009
    Messages:
    1,217
    Likes Received:
    130
    All those questions you have, I could answer ... for PalmOS. :eek: For Android, I'll just sit here quietly and hope somebody else comes by.
     
  7. rickyk586

    rickyk586 New Member

    Joined:
    Oct 7, 2010
    Messages:
    1
    Likes Received:
    0
    Let me know if you came/come up with anything!
     
  8. kevin@teslacoilsw

    kevin@teslacoilsw VIP Member VIP Member

    Joined:
    Jun 13, 2010
    Messages:
    183
    Likes Received:
    130
    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
    yes
    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.

    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".
     
  9. david.cheney

    david.cheney New Member

    Joined:
    Oct 11, 2010
    Messages:
    1
    Likes Received:
    0
    ... somebody else comes by and ... ;D

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

    Code (Text):
    1.  
    2. ActivityManager am = (ActivityManager)this.getSystemService(ACTIVITY_SERVICE);
    3. List<ActivityManager.RunningAppProcessInfo> apps = am.getRunningAppProcesses();
    4. List<ActivityManager.RecentTaskInfo> tasks = am.getRecentTasks(20,
    5.  ActivityManager.RECENT_WITH_EXCLUDED); // requires GET_TASKS perms!
    6.  
    and relatives?

    Interested in discussing possible apps?
     
  10. jonbonazza

    jonbonazza Well-Known Member

    Joined:
    Jul 13, 2010
    Messages:
    1,934
    Likes Received:
    458
    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 (Text):
    1.  
    2. <intent-filter>
    3.      <action android:name="android.intent.action.MAIN" />
    4.      <category android:name="android.intent.category.HOME" />
    5.      <category android:name="android.intent.category.DEFAULT" />
    6. </intent-filter>
    7.  
    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.
     

Share This Page

Loading...