簡體   English   中英

在Android中啟動主屏幕

[英]Launch home screen in android

我正在嘗試構建一個需要禁用android 4+版本中的主鍵的android應用,

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

我的問題是,當我想使用以下代碼返回到android啟動器“默認主屏幕”時:

         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.

我剛剛嘗試過,它對我有用。 我的應用程序在任何時候都不會被殺死。 我正在使用android 4.1

Intent startMain = new Intent(Intent.ACTION_MAIN);
    startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM