Api demo源码学习(5)App/Activity/Forwarding Activity跳转

这一节也非常简单,显示了一下Activity跳转的实现,直接上代码。

View Code
 1 public class Forwarding extends Activity
2 {
3 @Override
4 protected void onCreate(Bundle savedInstanceState)
5 {
6 super.onCreate(savedInstanceState);
7
8 setContentView(R.layout.forwarding);
9
10 // 设置Button监听事件,点击Button后,跳转到其他Activity,点返回按钮后不会再回到本Activity
11 Button goButton = (Button)findViewById(R.id.go);
12 goButton.setOnClickListener(mGoListener);
13 }
14
15 private OnClickListener mGoListener = new OnClickListener()
16 {
17 public void onClick(View v)
18 {
19 // Here we start the next activity, and then call finish()
20 // so that our own will stop running and be removed from the
21 // history stack.
22 //Activity跳转即new出一个Intent,通过startActivity实现跳转,最后用finish()函数结束本Activity的生命周期
23 Intent intent = new Intent();
24 intent.setClass(Forwarding.this, ForwardTarget.class);
25 startActivity(intent);
26 finish();
27 }
28 };
29 }
最后也别忘了再AndroidManifest.xml中注册一下跳转后的Activity。
<activity android:name="ForwardTarget"></activity>

以上即可。



原文地址:https://www.cnblogs.com/xutao1988/p/2286815.html