Created
January 22, 2014 16:31
-
-
Save showsky/8561956 to your computer and use it in GitHub Desktop.
Two launcher activity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | |
package="com.example.component" | |
android:versionCode="1" | |
android:versionName="1.0" > | |
<uses-sdk | |
android:minSdkVersion="15" | |
android:targetSdkVersion="15" /> | |
<application | |
android:allowBackup="true" | |
android:label="@string/app_name" | |
android:theme="@style/AppTheme" > | |
<activity | |
android:name="com.example.component.SetupActivity" | |
android:label="setup" | |
android:icon="@drawable/ic_launcher" | |
android:clearTaskOnLaunch="true" | |
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="com.example.component.MainActivity" | |
android:enabled="false" | |
android:icon="@drawable/ic_launcher" | |
android:label="main" > | |
<intent-filter> | |
<action android:name="android.intent.action.MAIN" /> | |
<category android:name="android.intent.category.LAUNCHER" /> | |
</intent-filter> | |
</activity> | |
</application> | |
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.component; | |
import android.app.Activity; | |
import android.os.Bundle; | |
import android.view.KeyEvent; | |
import android.view.Menu; | |
public class MainActivity extends Activity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.main); | |
} | |
@Override | |
public boolean onCreateOptionsMenu(Menu menu) { | |
// Inflate the menu; this adds items to the action bar if it is present. | |
getMenuInflater().inflate(R.menu.main, menu); | |
return true; | |
} | |
@Override | |
public boolean onKeyDown(int keyCode, KeyEvent event) { | |
if (keyCode == KeyEvent.KEYCODE_BACK) | |
finish(); | |
return super.onKeyDown(keyCode, event); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.component; | |
import android.app.Activity; | |
import android.content.ComponentName; | |
import android.content.Intent; | |
import android.content.pm.PackageManager; | |
import android.os.Bundle; | |
import android.util.Log; | |
import android.view.View; | |
import android.view.View.OnClickListener; | |
import android.widget.Button; | |
public class SetupActivity extends Activity { | |
private final static String TAG = "SetupActivity"; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
Log.v(TAG, "onCreate"); | |
setContentView(R.layout.setup); | |
((Button) findViewById(R.id.button1)).setOnClickListener(new OnClickListener() { | |
@Override | |
public void onClick(View arg0) { | |
toggleActivity(); | |
} | |
}); | |
} | |
@Override | |
protected void onDestroy() { | |
super.onDestroy(); | |
Log.v(TAG, "onDestory"); | |
} | |
private void toggleActivity() { | |
PackageManager pm = getPackageManager(); | |
pm.setComponentEnabledSetting( | |
new ComponentName(this, SetupActivity.class), | |
PackageManager.COMPONENT_ENABLED_STATE_DISABLED, | |
PackageManager.DONT_KILL_APP | |
); | |
pm.setComponentEnabledSetting( | |
new ComponentName(this, MainActivity.class), | |
PackageManager.COMPONENT_ENABLED_STATE_ENABLED, | |
PackageManager.DONT_KILL_APP | |
); | |
Intent intent = new Intent(this, MainActivity.class); | |
startActivity(intent); | |
finish(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment