다른 액티비티 상태에서 종료를 원할때
public class TestMain extends Activity { public static Activity mainAct; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mainAct = TestMain.this; } @Override protected void onDestroy() { ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE); am.restartPackage(getPackageName()); super.onDestroy(); } } public class TestSub extends Activity implements OnClickListener { public void onClick (View v){ //어딘가에 종료를 원하는 상황에서 TestMain mAct = (TestMain) TestMain.mainAct; mAct.finish(); finish(); //현재 액티비티를 먼저 종료하면 안됨 } }
//AndroidManifest.xml <uses-permission android:name="android.permission.RESTART_PACKAGES"/>
이렇게 하면 됨
답글 남기기