0

I'm trying to build an android app which needs to disable a home key in android version 4+ ,

  <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" 
                />

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

My problem is when i want to return to android launcher "default home screen" using this code :

         PackageManager p = getPackageManager();
         ComponentName cN = new ComponentName(MainActivity.this, MainActivity.class);
         p.setComponentEnabledSetting(cN, PackageManager.COMPONENT_ENABLED_STATE_ENABLED,      PackageManager.DONT_KILL_APP);
         p.setComponentEnabledSetting(cN, PackageManager.COMPONENT_ENABLED_STATE_DISABLED,  PackageManager.DONT_KILL_APP);

  the default home screen lunched but the application is killed .

  How I can  lunch the home screen without killing the application.
opalenzuela
  • 3,139
  • 21
  • 41
jessi
  • 1
  • 1
  • 2
  • Please try this, it might help you [Launching default android launcher][1] [1]: http://stackoverflow.com/questions/6705847/launching-default-android-launcher-programmatically – Rohit5k2 Nov 05 '13 at 10:15
  • I've tried this before,didn't work for me. – jessi Nov 05 '13 at 10:17
  • I've tried this before also, and I'm pretty sure the DONT_KILL_APP flag also did not work for me. – Jo Jo Nov 05 '13 at 10:17

1 Answers1

1

I tried it just now and its working for me. My application is not killed at any point. I am using android 4.1

Intent startMain = new Intent(Intent.ACTION_MAIN);
    startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);
Rohit5k2
  • 17,948
  • 8
  • 45
  • 57
  • One last thing I would like you to check. Go to android settings > Developer Options > Do not keep activities. Make sure this field is not checked. – Rohit5k2 Nov 05 '13 at 10:45
  • I tried this solution just now , but my app is disappeared from application list – jessi Nov 05 '13 at 10:54
  • This is really strange. My "Do not keep activities" field is unchecked and same is code working for me. Let me try something else now. – Rohit5k2 Nov 05 '13 at 10:56