I have an task switching app on the Android Market called AppSwipe! and one of the most commonly requested features is the ability to launch my app by long-pressing the home button. Since this is not possible, I created a way to launch AppSwipe! by double-pressing the home key.
This feature has been out for over a year and my users love it. However, I recently received an email from one user who was reporting some strange behavior when using this functionality... essentially, the home app is getting killed and taking a long time to restart. When this occurs there are some other UI issues as well (such as folders launching with transparent backgrounds and such). It only happens on very specific devices and I can't reproduce the problem. Here is the general process that I am using to implement the double- press of the home button: 1) I created an activity that declares itself as a home replacement app (see XML below) 2) I have a user-modifiable setting that allows the user to specify which home app to launch from the home button. 3) When the home button is pressed, my "home replacement" activity has the following logic: a) The first time the home button is pressed a timer is created and started in onResume() b) If the timer finishes, then the user-specified home app is launched c) If home is pressed again and the timer is still running, then I cancel the timer and launch my app Here is the XML that declares my "home replacement" app: <activity android:theme="@android:style/Theme.Translucent.NoTitleBar" android:name=".HomeLauncherActivity" android:label="@string/app_home_launcher_label" android:launchMode="singleInstance" android:stateNotNeeded="true" > <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> </activity> Here is the onResume() method that runs the timer: @Override public void onResume() { super.onResume(); if (m_prefMgr == null) m_prefMgr = PreferenceManager.getDefaultSharedPreferences(this); if (m_pkgMgr == null) m_pkgMgr = getPackageManager(); //First Home Button Press if (m_timer == null) { int launchThreshold = m_prefMgr.getInt(getString(R.string.pref_button_launch_home_click_threshold_key), PrefSettings.DEFAULT_DOUBLE_PRESS_HOME_THRESHOLD); m_timer = new AppSwipeHomeLaunchTimer(launchThreshold, launchThreshold); m_timer.start(); } else //Second Home Button Press { m_timer.cancel(); m_timer = null; boolean swapHomePress = m_prefMgr.getBoolean(getString(R.string.pref_button_launch_swap_buttons_key), PrefSettings.DEFAULT_SWAP_HOME_BUTTON_BEHAVIOR); if (swapHomePress) launchHomeApp(); else launchAppSwipe(); } } Here is the code for my launchHomeApp() method: public void launchHomeApp() { try { String pkgName = m_prefMgr.getString(getString(R.string.pref_button_launch_default_home_app_pkg_key), ""); String className = m_prefMgr.getString(getString(R.string.pref_button_launch_default_home_app_class_key), ""); Intent launchIntent = new Intent(Intent.ACTION_MAIN); launchIntent.addCategory(Intent.CATEGORY_HOME); launchIntent.setComponent(new ComponentName(pkgName, className)); launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(launchIntent); finish(); } catch(ActivityNotFoundException e) { launchAppSettings(R.string.error_select_home_app); } } Any ideas on what can be done? One interesting thing to note is that the user who reported this problem said that if they use ADW.Launcher as the home app and turn on the "System Persistent" option (which is supposed to prevent the Android OS from killing it) then the problem goes away. -- 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