Android学习篇章7-Activity退出方式1递归退出

public class BasicActivity extends Activity{

	
	public static final int EXIST_CODE=0x101; 
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
	}
	
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {

		if(resultCode==EXIST_CODE)
		{
			this.MyRecursionEXIST();
		}
		super.onActivityResult(requestCode, resultCode, data);
	}
	
	
	public void MyRecursionEXIST()
	{
		this.setResult(EXIST_CODE);
		this.fileList();
		//System.exit(0);//这种方式下 为了所有的Activity都经过销毁的周期  最好不要强制退出进程
        //这样所有Acitvity关闭后会留下一个空进程
	}
}


public class MainActivity extends BasicActivity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_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;
	}

	public void btn_Click(View view)
	{
		Intent intent=new Intent();
		intent.setClass(this, SecondActivity.class);
		startActivityForResult(intent, 0x101);
	}
}

public class ThirdActivity extends BasicActivity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_third);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.third, menu);
		return true;
	}
	
	public void btn_Click(View view)
	{
		this.MyRecursionEXIST();
	}

}


    



你可能感兴趣的:(Android,基础)