android(32)(任务栈)

来源:互联网 发布:epson l101清零软件 编辑:程序博客网 时间:2024/04/28 03:21
1.布局文件:<LinearLayout 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"    android:orientation="vertical"    tools:context=".MainActivity" >    <TextView           android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:text="我是界面01"        android:textSize="30sp"        />    <Button        android:onClick="open01"        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:text="开启界面01" />    <Button        android:onClick="open02"        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:text="开启界面02" /></LinearLayout><LinearLayout 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"    android:orientation="vertical"    tools:context=".MainActivity" >    <TextView        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:text="我是界面02"        android:textSize="30sp" />    <Button        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:onClick="open01"        android:text="开启界面01" />    <Button        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:onClick="open02"        android:text="开启界面02" /></LinearLayout>2.业务逻辑代码:public class MainActivity extends Activity {    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        System.out.println("01activity被创建了。任务栈id:"+getTaskId());    }    public void open01(View view){        Intent intent = new Intent(this,MainActivity.class);        startActivity(intent);    }    public void open02(View view){        Intent intent = new Intent(this,SecondActivity.class);        startActivity(intent);    }}public class SecondActivity extends Activity {    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_second);        System.out.println("02activity被创建了。任务栈id:"+getTaskId());    }    public void open01(View view){        Intent intent = new Intent(this,MainActivity.class);        startActivity(intent);    }    public void open02(View view){        Intent intent = new Intent(this,SecondActivity.class);        startActivity(intent);    }    @Override    protected void onNewIntent(Intent intent) {        System.out.println("02activityonnew intnet。任务栈id:"+getTaskId());        super.onNewIntent(intent);    }}
0 0