实验二——任务三——理解Task
来源:互联网 发布:2008 科比 知乎 编辑:程序博客网 时间:2024/06/01 07:55
任务3:理解Task
app1的activity1有两个按钮,一个按钮跳转到Activity2,另外一个按钮跳转到打电话的页面,打电话这个功能不属于app1,我们假设它为app2。
首先默认进入app1的activity1,点击button1后跳转到activity2,再点击activity2的按钮后跳转到activity1,再点击button2跳转到打电话页面,最后依次点返回按钮,大家看Task栈效果。
1.运行效果图
核心代码
主活动MainActivity:
package com.example.thirdlab;import android.net.Uri;import android.os.Bundle;import android.app.Activity;import android.content.Intent;import android.view.Menu;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;public class MainActivity extends Activity{ private Button button1; private Button button2;@Overrideprotected void onCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);button1 = (Button)findViewById(R.id.but_no1);button2 = (Button)findViewById(R.id.but_no2);button1.setOnClickListener(new OnClickListener(){@Overridepublic void onClick(View arg0){// TODO Auto-generated method stubIntent intent = new Intent(MainActivity.this,SecondActivity.class);startActivity(intent);}});button2.setOnClickListener(new OnClickListener(){@Overridepublic void onClick(View arg0){// TODO Auto-generated method stubIntent intent1=new Intent(Intent.ACTION_DIAL);intent1.setData(Uri.parse("tel:10086"));startActivity(intent1);}});}@Overridepublic boolean onCreateOptionsMenu(Menu menu){// Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate(R.menu.main, menu);return true;}}
主活动布局:
<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" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MainActivity" > <Button android:id="@+id/but_no1" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/text_but1" /> <Button android:id="@+id/but_no2" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@id/but_no1" android:text="@string/text_but2" /> </RelativeLayout>
第二个活动:
package com.example.thirdlab;import android.os.Bundle;import android.app.Activity;import android.content.Intent;import android.view.Menu;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;public class SecondActivity extends Activity{ private Button button;@Overrideprotected void onCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.activity_second);button = (Button) findViewById(R.id.but2_no1);button.setOnClickListener(new OnClickListener(){@Overridepublic void onClick(View arg0){// TODO Auto-generated method stubIntent intent = new Intent(SecondActivity.this,MainActivity.class);startActivity(intent);}});}@Overridepublic boolean onCreateOptionsMenu(Menu menu){// Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate(R.menu.second, menu);return true;}}
第二个布局:
<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" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".SecondActivity" > <Button android:id="@+id/but2_no1" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/text_but3" /></RelativeLayout>
0 0
- 实验二——任务三——理解Task
- 实验二--任务三--理解Task
- 实验二.任务三.TASK
- 实验二_任务三_理解Task
- 实验二——任务三
- 初学移动开发技术_实验二_任务三_理解Task
- 实验二—任务一
- 任务三 理解Task
- 任务三::理解Task。
- 实验任务3 理解Task
- 实验二———任务一
- 实验二——任务二体重测量计
- 实验二——任务一——打招呼
- python——定时任务task
- c++程序设计实验报告——任务(二)
- 实验二—任务2:标准体重计算器--------------闪退
- freertos内核走读2——task任务调度机制(二)
- 实验2 Activity和Intent-任务3:理解Task
- flask关于请求方法
- 初学者笔记
- 读模式与写模式
- 【C语言】比较两个数组中是否有相同的元素
- 64位ubuntu kylin 16.04下制作tiny4412可用的SD启动卡
- 实验二——任务三——理解Task
- 表达式前后缀表达形式
- HDU 5877 - Weak Pair
- 面向对象程序设计上机练习七(类和对象)
- WPF教程(五) XAML是什么?
- Spring MVC 之@ModelAttribute使用
- day21 XML
- hihoCoder #1135 : Magic Box
- caffe中cifar10的full_train模型出现nan的解决办法