Activity生命周期以及Intent两种画面跳转方式
来源:互联网 发布:爱奇艺网络机顶盒版 编辑:程序博客网 时间:2024/06/06 06:44
Activity的生命周期
onCreate();创建
onStart();运行
onResume();获取焦点
onPasue();失去焦点
onStop();暂停
onDestroy();销毁
onRestart();
–活动状态(Active/Running) Activity处于界面最顶端,获取焦点
–暂停状态(Paused) Activity失去焦点,但对用户可见
–停止状态(Stopped) Activity被完全遮挡,但保留所有状态和成员信息
–非活动状态(Killed)Activity被停止
什么是Intent
Intent可以理解为信使(意图)
由Intent来协助完成Android各个组件之间的通讯
Intent 包括两种跳转方式
1.无返回结果的跳转方式:
import android.app.Activity;import android.content.Intent;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;public class FirstActivity extends Activity{private Button btn;@Overrideprotected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_first); btn = (Button) findViewById(R.id.button1); btn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(FirstActivity.this,SActivity.class); startActivity(intent); } });}}
2.有返回结果的页面跳转
第一个画面public class FirstActivity extends Activity{ private Button btn; private TextView tv; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_first); tv = (TextView) findViewById(R.id.mTextView); btn = (Button) findViewById(R.id.button2); btn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(FirstActivity.this,SActivity.class); startActivityForResult(intent, 1); } }); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode==1 && resultCode ==2) { String context = data.getStringExtra("data"); tv.setText(context); } }}第二个跳转画面public class SActivity extends Activity{ private Button btn; private String datas = "hello word"; @Override protected void onCreate(Bundle savedInstanceState) { // TODO 自动生成的方法存根 super.onCreate(savedInstanceState); setContentView(R.layout.activity_seconed); btn = (Button) findViewById(R.id.button3); btn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent data = new Intent(); data.putExtra("data", datas); setResult(2, data); finish(); } }); }}<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <Button android:id="@+id/button1" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="启动第一个页面" /> <Button android:id="@+id/button2" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="启动第二个页面" /> <TextView android:id="@+id/mTextView" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="显示返回结果" /></LinearLayout><?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <Button android:id="@+id/button3" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="点击返回" /></LinearLayout>
阅读全文
0 0
- Activity生命周期以及Intent两种画面跳转方式
- Activity入门--“生命周期”,启动模式,Intent跳转Flag方式
- Intent的两种跳转方式
- Intent 启动 Activity的两种方式
- activity的两种跳转方式
- Activity生命周期的应用场景举例以及显隐式Activity启动的两种方式和启动系统常见的ACtivity
- Intent实现Activity跳转的三种方式
- intent的使用以及activity的生命周期
- 生命周期和画面跳转
- Intent启动活动以及Intent传递数据&activity的生命周期
- Activity的通常的两种跳转方式
- Activity生命周期,启动模式LaunchMode,碎片Fragment,Intent跳转传递
- Android Service的两种启动方式以及生命周期
- Activity的生命周期以及两个activity之间跳转的问题
- Activity的跳转方式:1.intent.addFlags(),2.四种launchMode
- Intent 跳转Activity
- intent 跳转activity无效
- Intent 实现Activity跳转
- 一道让人很生气的题C. Tanya and Toys
- libpcap使用
- Segmentation fault (core dumped)出错原因及位置分析
- Android深入浅出之Binder机制
- 【华为机试】公共字串计算
- Activity生命周期以及Intent两种画面跳转方式
- 1012. 数字分类 (20)
- 《Noisy Activation Function》噪声激活函数
- Python语法基础02.变量及类型
- C文件调用C++文件里的函数
- 原生Ajax实现异步数据传输
- 教你打造绚丽多彩的TextView
- 程序员快来看!经典代码替你省去多少时间?
- dubbo中几种protocol的理解