안드로이드 프로그램 종료…

다른 액티비티 상태에서 종료를 원할때

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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(); //현재 액티비티를 먼저 종료하면 안됨
}
}
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(); //현재 액티비티를 먼저 종료하면 안됨 } }
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(); //현재 액티비티를 먼저 종료하면 안됨
	 }
}
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
//AndroidManifest.xml
<uses-permission android:name="android.permission.RESTART_PACKAGES"/>
//AndroidManifest.xml <uses-permission android:name="android.permission.RESTART_PACKAGES"/>
//AndroidManifest.xml
<uses-permission android:name="android.permission.RESTART_PACKAGES"/>

이렇게 하면 됨


Comments

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다