Posts

Showing posts with the label activity

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

How to kill an Android activity?

 How to kill an Android activity when leaving it so that it cannot be accessed from the back button? All you need to do is call finish() method in Activity class like following code snippets. Intent intent = new Intent ( this , NextActivity . class ); startActivity ( intent ); finish ();

Exiting an Application Activity

I didn't check this, because normally in android you not exit from the app, android os take the garbage collection for the app. So here is the code for existing from an activity. exitButton = (Button)findViewById(R.id.exit_button); exitButton.setOnClickListener( new Button.OnClickListener() { public void onClick (View v){ Log.d(TAG, v.toString() + ": Leaving activity..."); Runtime.getRuntime().exit(0); } } );