jessi
jessi

Reputation: 1

Launch home screen in android

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.

Upvotes: 0

Views: 923

Answers (1)

Rohit5k2
Rohit5k2

Reputation: 18112

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);

Upvotes: 1

Related Questions