Android学习笔记01-Activity
来源:互联网 发布:知乎登录注册页面实现 编辑:程序博客网 时间:2024/06/16 17:49
Android学习笔记01-Activity
1.创建Activity
import android.app.Activity;import android.os.Bundle;public class SecondActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_second); }}
2.快捷创建监听器
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="click1" />
public void click1(View v){ //创建意图,这个是隐式意图 Intent intent = new Intent(); //设置动作 intent.setAction(Intent.ACTION_CALL); intent.setData(Uri.parse("tel:110")); //启动Activity startActivity(intent); }
3.显示启动
//显式启动SecondActivity public void click2(View v){ //这个是显式意图 Intent intent = new Intent(); //设置上下文和目标Activity的字节码 intent.setClass(this, SecondActivity.class); startActivity(intent); }
//显式启动拨号器 public void click3(View v){ Intent intent = new Intent(); //arg0:目标Activity所在的应用的包名 //arg1:目标Activity的类名,注意要带上包名 intent.setClassName("com.android.dialer", "com.android.dialer.DialtactsActivity"); intent.setData(Uri.parse("tel:11670")); startActivity(intent); }
//显示启动浏览器 public void click6(View v){ Intent intent = new Intent(); intent.setClassName("com.android.browser", "com.android.browser.BrowserActivity"); startActivity(intent); }
4.隐式启动
//隐式跳转至打电话Activity public void click1(View v){ //创建意图,这个是隐式意图 Intent intent = new Intent(); //设置动作 intent.setAction(Intent.ACTION_CALL); intent.setData(Uri.parse("tel:110")); //启动Activity startActivity(intent); }
/** * 隐式启动拨号器 */ public void click4(View v){ Intent intent = new Intent(); intent.setAction(Intent.ACTION_DIAL); intent.setData(Uri.parse("tel:76115230")); startActivity(intent); }
<activity android:name=".SecondActivity"> <intent-filter > <action android:name="a.b.c"/> <action android:name="a.b.c3"/> <data android:scheme="heima"/> <data android:scheme="heima3" android:mimeType="text/name"/> <category android:name="android.intent.category.DEFAULT"/> </intent-filter> <intent-filter > <action android:name="a.b.c2"/> <data android:scheme="heima2"/> <category android:name="android.intent.category.DEFAULT"/> </intent-filter> </activity>
/** * 隐式启动SecondActivity */ public void click5(View v){ Intent intent = new Intent(); intent.setAction("a.b.c"); //匹配mimetype// intent.setType("text/name"); //匹配scheme// intent.setData(Uri.parse("heima:春眠不觉晓")); intent.setDataAndType(Uri.parse("heima:春眠不觉晓"), "text/name"); //如果没有设置Category的匹配,那么自动匹配CATEGORY_DEFAULT// intent.addCategory(Intent.CATEGORY_DEFAULT); startActivity(intent); }
5.Intent数据封装
//跳转到SecondActivity,在second中做姻缘计算 Intent intent = new Intent(this, SecondActivity.class); //把数据封装至intent中 //intent中可以封装数据,数据有八大基本数据类型和字符串及它们的数组,还有实现了序列化接口的对象,还有bundle对象// intent.putExtra("maleName", maleName);// intent.putExtra("femaleName", femaleName); //Bundle中也可以用键值对封装数据,封装类型与intent一致 Bundle extras = new Bundle(); extras.putString("maleName", maleName); extras.putString("femaleName", femaleName); intent.putExtras(extras); startActivity(intent);
Intent intent = getIntent();// String maleName = intent.getStringExtra("maleName");// String femaleName = intent.getStringExtra("femaleName"); Bundle bundle = intent.getExtras(); String maleName = bundle.getString("maleName"); String femaleName = bundle.getString("femaleName");
6.简单姻缘核心代码
String text = maleName + femaleName; byte[] b = text.getBytes(); int total = 0; for (byte c : b) { total += c; } int yanyuan = Math.abs(total) % 101;
7.横竖屏问题
<activity android:screenOrientation="portrait" android:name="com.itheima.lifecycle.MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>
//写死横屏 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
8.启动模式
<activity android:launchMode="singleInstance" android:name="com.itheima.runmode.SecondActivity"></activity>
android:launchMode="standard"android:launchMode="singleInstance"android:launchMode="singleTop"android:launchMode="singleTask"
9.隐式启动
10.隐式启动
11.隐式启动
12.隐式启动
13.隐式启动
0 0
- Android学习笔记01-Activity
- Android学习笔记----Activity
- android学习Activity笔记
- Android学习笔记-Activity
- Android 学习笔记--Activity
- android 学习笔记 1 activity
- android学习笔记之Activity
- android学习笔记1(activity)
- Android学习笔记:Activity-Spinner
- android开发学习笔记--activity
- Android学习笔记 - Activity篇
- Android学习笔记:Activity-Spinner
- Android学习笔记:Activity-Spinner
- Android学习笔记:Activity-Spinner
- Android学习笔记1:Activity
- Android学习笔记--Activity概述
- Android学习笔记 - Activity篇
- Android学习笔记:Activity-ListView
- Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK黑屏问题
- shell之用while从文件中读取数据
- Activity四种启动模式(standard,singleTop,singleTask,singleInstance)
- VLC2.2.1 在vs2013中编译
- 数据仓库---企业信息工厂(EIF)
- Android学习笔记01-Activity
- 多点触控
- MySQL之innodb数据库引擎
- 杭电2844
- poj 1036 Gangsters lis
- 圆形ImageView
- 23种设计模式(10):命令模式
- python第三方爬虫开源库scrapy学习笔记
- opencv在visual studio的配置技巧