Posts

Showing posts from November, 2015

How to disable Activity and enable it programmatically?

In this example there are two activities declared in AndroidManifest.xml file. SetupActivity is enabled and MainActivity is disabled by default.

<activity
      android:name=”.SetupActivity”
      android:label=”@string/app_name_setup”
      android:icon=”@drawable/app_setup_icon”
      android:enabled=”true”>
         <intent-filter>
             <action android:name=”android.intent.action.MAIN”/>
             <category android:name=”android.intent.category.LAUNCHER”/>
         </intent-filter>
</activity>
<activity
      android:name=”.MainActivity”
      android:label=”@string/app_name”
      android:icon=”@string/app_icon”
      android:enabled=”false”>
         <intent-filter>
             <action android:name=”android.intent.action.MAIN”/>
             <category android:name=”android.intent.category.LAUNCHER”/>
         </intent-filter>
</activity>

You can enable MainActivity by using following code.

private void toggleActivitie…