1 package com.example.activitydialog;
2
3 import android.app.Activity;
4 import android.content.Intent;
5 import android.os.Bundle;
6 import android.view.Menu;
7 import android.view.View;
8 import android.view.View.OnClickListener;
9 import android.widget.Button;
10
11 public class MainActivity extends Activity {
12
13 private Button btn = null;
14
15 @Override
16 protected void onCreate(Bundle savedInstanceState) {
17 System.out.println("MainActivity onCreate");
18 // TODO Auto-generated method stub
19 super.onCreate(savedInstanceState);
20 setContentView(R.layout.activity_main);
21
22 btn = (Button)findViewById(R.id.btnMain);
23 //pop a dialog activity.
24 btn.setOnClickListener(new OnClickListener() {
25
26 @Override
27 public void onClick(View v) {
28 Intent intent = new Intent(MainActivity.this, DialogActivity.class);
29 startActivity(intent);
30 }
31 });
32 }
33
34 @Override
35 protected void onDestroy() {
36 System.out.println("MainActivity onDestroy");
37 // TODO Auto-generated method stub
38 super.onDestroy();
39 }
40
41 @Override
42 protected void onPause() {
43 System.out.println("MainActivity onPause");
44 // TODO Auto-generated method stub
45 super.onPause();
46 }
47
48 @Override
49 protected void onRestart() {
50 System.out.println("MainActivity onRestart");
51 // TODO Auto-generated method stub
52 super.onRestart();
53 }
54
55 @Override
56 protected void onResume() {
57 System.out.println("MainActivity onResume");
58 // TODO Auto-generated method stub
59 super.onResume();
60 }
61
62 @Override
63 protected void onStart() {
64 System.out.println("MainActivity onStart");
65 // TODO Auto-generated method stub
66 super.onStart();
67 }
68
69 @Override
70 protected void onStop() {
71 System.out.println("MainActivity onStop");
72 // TODO Auto-generated method stub
73 super.onStop();
74 }
75
76
77 @Override
78 public boolean onCreateOptionsMenu(Menu menu) {
79 // Inflate the menu; this adds items to the action bar if it is present.
80 getMenuInflater().inflate(R.menu.main, menu);
81 return true;
82 }
83
84 }