Skip to content

Commit e5ebf0d

Browse files
committed
init
1 parent 3f0ae48 commit e5ebf0d

File tree

4 files changed

+106
-0
lines changed

4 files changed

+106
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.example.navigator;
2+
3+
public class ActivityNameConstants {
4+
public final static String SecondActivity
5+
= "com.example.navigator.SecondActivity";
6+
}
7+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.example.navigator;
2+
3+
import android.app.Activity;
4+
import android.content.Intent;
5+
6+
public abstract class BaseActivity extends Activity {
7+
8+
public void navigateTo(final String activityName,
9+
final Intent intent) {
10+
11+
//在这个位置执行页面打点的操作,这里可以利用到activityName
12+
13+
Class<?> clazz = null;
14+
try {
15+
clazz = Class.forName(activityName);
16+
if (clazz != null) {
17+
intent.setClass(this, clazz);
18+
this.startActivity(intent);
19+
}
20+
} catch (final ClassNotFoundException e) {
21+
return;
22+
}
23+
}
24+
}
25+
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.example.navigator;
2+
3+
import android.content.Intent;
4+
import android.os.Bundle;
5+
import android.view.Menu;
6+
import android.view.View;
7+
import android.widget.Button;
8+
9+
public class MainActivity extends BaseActivity {
10+
11+
Button btnNav1, btnNav2;
12+
13+
@Override
14+
protected void onCreate(Bundle savedInstanceState) {
15+
super.onCreate(savedInstanceState);
16+
setContentView(R.layout.activity_main);
17+
18+
btnNav1 = (Button) findViewById(R.id.btnNav1);
19+
btnNav1.setOnClickListener(new View.OnClickListener() {
20+
@Override
21+
public void onClick(View v) {
22+
Intent intent = new Intent(MainActivity.this,
23+
SecondActivity.class);
24+
startActivity(intent);
25+
}
26+
});
27+
28+
btnNav2 = (Button) findViewById(R.id.btnNav2);
29+
btnNav2.setOnClickListener(new View.OnClickListener() {
30+
@Override
31+
public void onClick(View v) {
32+
Intent intent = new Intent();
33+
intent.putExtra("name", "Jianqiang");
34+
navigateTo(ActivityNameConstants.SecondActivity, intent);
35+
}
36+
});
37+
}
38+
39+
@Override
40+
public boolean onCreateOptionsMenu(Menu menu) {
41+
// Inflate the menu; this adds items to the action bar if it is present.
42+
getMenuInflater().inflate(R.menu.activity_main, menu);
43+
return true;
44+
}
45+
46+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.example.navigator;
2+
3+
import android.app.Activity;
4+
import android.os.Bundle;
5+
import android.view.Menu;
6+
import android.widget.TextView;
7+
8+
public class SecondActivity extends Activity {
9+
10+
TextView tv;
11+
12+
@Override
13+
protected void onCreate(Bundle savedInstanceState) {
14+
super.onCreate(savedInstanceState);
15+
setContentView(R.layout.activity_second);
16+
17+
Bundle bundle = getIntent().getExtras();
18+
String name = bundle.getString("name");
19+
}
20+
21+
@Override
22+
public boolean onCreateOptionsMenu(Menu menu) {
23+
// Inflate the menu; this adds items to the action bar if it is present.
24+
getMenuInflater().inflate(R.menu.activity_sceond, menu);
25+
return true;
26+
}
27+
28+
}

0 commit comments

Comments
 (0)