Activity学习认知
来源:互联网 发布:微星知乎 编辑:程序博客网 时间:2024/06/01 10:29
1.activity生命周期
The entire lifecycle of an activity is defined by the following Activity methods. All of these are hooks that you can override to do appropriate work when the activity changes state. All activities will implement onCreate(Bundle)
to do their initial setup; many will also implement onPause()
to commit changes to data and otherwise prepare to stop interacting with the user. You should always call up to your superclass when implementing these methods.
翻译:activity的全部生命周期通过以下几个方法定义。当activity的状态变化时你可以根据功能来重写相应的方法。所有的activity必须实现onCreate(Bundle)
来初始化;当打算提交更改的数据或者停止与用户的互动是可能需要重写onPause()
方法。当重写这些方法时你必须调用父类的方法。
2.activity间的跳转和值传递
显式跳转
public class MainActivity extends Activity {private EditText nameEt;private Button ceshiBtn;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);nameEt = (EditText)findViewById(R.id.nameEt);ceshiBtn = (Button)findViewById(R.id.ceshiBtn);Intent intent = new Intent(this,RpCaculatorActivity.class);startActivity(intent); //startActivityForResult(intent, 1000);}}
隐式跳转
public class MainActivity extends Activity {private EditText nameEt;private Button ceshiBtn;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);nameEt = (EditText)findViewById(R.id.nameEt);ceshiBtn = (Button)findViewById(R.id.ceshiBtn);Intent intent = new Intent("com.example.rpcaculator.test2"); startActivity(intent); //startActivityForResult(intent, 1000);}}
如果通过startActivityForResult这个方法进行activity跳转的可以获取传回值。
值传递:1、直接通过intent的自带的方法进行值传递,其传值可以使字符串、对象、list等具体可以查看其方法。
如:Intent intent = new Intent(this,RPCacultorActivity.class);
intent.intent.putExtra("name", "1111");
在下一个activity中可以通过以下方式获得
Intent intent = this.getIntent();
String name = intent.getStringExtra("name");
2、通过Bundle进行数据传递
如:Intent intent = new Intent(this,RPCacultorActivity.class);
Bundle data = new Bundle();
data.putString("name","liu");
intent.putExtras(data);
在下一个activity中通过以下方式获得相应值:
Bundle data = this.getIntent().getExtras();
String name = data.getString("name");
- Activity学习认知
- 认知心理学学习笔记
- MIS第一章学习认知
- 学习算法的认知
- 嵌入式系统学习认知
- ThreadLocal认知学习
- 学习能力与认知
- 深度学习Batch_Size认知
- 日语学习的基础认知
- 对Java学习的认知
- JAVA认知学习之JVM
- RecyclerView学习(一)----初步认知
- 认知计算与深度学习
- 认知计算与深度学习
- 认知
- 认知
- 认知
- 认知
- 如何成功运行SDL官方提供的Android平台的Demo
- 硬链接和符号链接
- 音频和视频同步ffplay5原理
- 贫农的大数据之五(Hadoop集群部署)
- C#开发android之alertdialog用法
- Activity学习认知
- 超棒的翻译--ASIHTTPRequest使用指南
- CloudStack + XenServer 部署 – 高级网络功能应用(10)
- ntohl(),htonl(),ntohs()
- A*算法入门--A* Pathfinding for Beginners
- 下载visual studio
- Java 枚举7常见种用法
- Redis数据类型
- Lucene实战(一)Lucene介绍及HelloWorld运行(附Eclipse工程)