Activityのfinish()メソッドの上書き
1989 ワード
MainActivityは次のとおりです.
main.xmlは次のとおりです.
package cn.testfinish;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
/**
* Demo :
* Activity finish()
* finish() , onDestroy()
* Activity finish() , finish()
* finish() onDestroy() .
*/
public class MainActivity extends Activity {
private Button mButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
init();
}
private void init(){
mButton=(Button) findViewById(R.id.button);
mButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
MainActivity.this.finish();
}
});
}
@Override
public void finish() {
super.finish();
System.out.println(" finish() ");
}
@Override
protected void onDestroy() {
super.onDestroy();
System.out.println(" Activity onDestroy() ");
}
}
main.xmlは次のとおりです.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="click here"
android:layout_centerInParent="true"
/>
</RelativeLayout>