Android-activity-intent
package com.hanqi.myapplication; import android.content.ComponentName;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button; public class MainActivity extends AppCompatActivity { //回调方法 (on开头的方法都是)
//在创建时自动调用
@Override
protected void onCreate(Bundle savedInstanceState) {
//调用父类的回调方法
super.onCreate(savedInstanceState);
//设置内容视图文件
//建立Activity和Layout文件之间的关联
setContentView(R.layout.test_linearlayout);
//1.获得这个组件
Button bt2 = (Button)findViewById(R.id.button2);
//2.操作这个组件
// bt2.setText("新按钮");
//日志输出
System.out.print("日志输出=应用开始运行");
Log.v("HANQI", "Verbose级别的日志信息");
Log.d("HANQI", "Debug级别的日志信息");
Log.i("HANQI", "Info级别的日志信息");
Log.w("HANQI", "Warning级别的日志信息");
Log.e("HANQI", "Error级别的日志信息");
}
public void login_onClick(View v)
{
//打开新的Activity
//1.创建意图 显式意图
Intent intent = new Intent();
//定义显式意图
ComponentName componentName = new ComponentName(this,TextActivity.class);
intent.setComponent(componentName);
intent.putExtra("name", "意图传递的值");
intent.putExtra("name1", "意图传递的值1"); //2.发起意图
startActivity(intent);
}
public void bt2_onClick(View v)
{
//发起隐式意图
//打开拨打电话的界面
//系统已经预先定义了常用功能的Action的字符串常量
Intent intent2 = new Intent(Intent.ACTION_DIAL);
//intent2.setAction(Intent.ACTION_DIAL); //构造Uri
Uri uri = Uri.parse("tel:110"); //intent2.addCategory(""); //设置data
intent2.setData(uri); //intent2.setType("");
//intent2.setDataAndType(uri,"");
startActivity(intent2);
} public void bt3_onClick(View v)
{
//返回桌面
Intent intent3 = new Intent(Intent.ACTION_MAIN);
intent3.addCategory(Intent.CATEGORY_HOME);
startActivity(intent3);
}
}
package com.hanqi.myapplication; import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast; //1.继承Activity
/**
* Created by lenovo on 2016/4/22.
*/
public class TextActivity extends Activity { //成员变量
EditText et1;
EditText et2;
EditText et3;
//2.重写onCreate(),关联Layout文件
//onCreate()是一个回调方法:在满足特定条件下自动调用的方法;方法名一般on开头 @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); //关联
setContentView(R.layout.message_relativelayout);
//初始化工作
//获取Layout文件中定义的组件 et1=(EditText)findViewById(R.id.et1);
et2=(EditText)findViewById(R.id.et2);
et3=(EditText)findViewById(R.id.et3);
Log.e("TAG","onCreat()被调用"); //得到意图
Intent intent = getIntent();
String strname = intent.getStringExtra("name");
String strname1 = intent.getStringExtra("name1");
//intent.getExtras();
Log.e("TAG","意图传递的数据="+strname);
Log.e("TAG","意图传递的数据1="+strname1);
// if(savedInstanceState!=null&&!savedInstanceState.isEmpty())
// {
// et1.setText(savedInstanceState.getString("et1")+"恢复之后的");
// et2.setText(savedInstanceState.getString("et2"));
// et3.setText(savedInstanceState.getString("et3"));
// }
} //保存状态
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
Log.e("TAG", "保存应用状态"); outState.putString("et1", et1.getText().toString());
outState.putString("et1",et2.getText().toString());
outState.putString("et1",et3.getText().toString());
} //恢复状态
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
Log.e("TAG", "恢复应用状态"); et1.setText(savedInstanceState.getString("et1")+"恢复之后的");
et2.setText(savedInstanceState.getString("et2"));
et3.setText(savedInstanceState.getString("et3")); } //启动
@Override
protected void onStart() {
super.onStart();
Log.e("TAG","onStart()被调用");
}
//重启
@Override
protected void onRestart() {
super.onRestart();
Log.e("TAG", "onRestart()被调用");
}
//继续
@Override
protected void onResume() {
super.onResume();
Log.e("TAG", "onResume()被调用");
}
//暂停
@Override
protected void onPause() {
super.onPause();
Log.e("TAG", "onPause()被调用");
}
//停止
@Override
protected void onStop() {
super.onStop();
Log.e("TAG", "onStop()被调用");
}
//销毁
@Override
protected void onDestroy() {
super.onDestroy();
Log.e("TAG", "onDestroy()被调用");
}
//点击事件方法
public void bt_OnClick(View v)
{
//显示提示信息
//方法链
Toast.makeText(TextActivity.this, "消息发送成功", Toast.LENGTH_SHORT).show();
}
public void close_OnClick(View v)
{
//关闭应用
finish();
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"> <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="用户名:"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="请输入用户名"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="密码:"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="请输入密码"
android:inputType="textPassword"
android:maxLength="6"/>
</LinearLayout> <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="显式意图"
android:id="@+id/button"
android:layout_weight="1"
android:onClick="login_onClick"/> <Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="隐式意图"
android:id="@+id/button3"
android:layout_weight="1"
android:onClick="bt2_onClick"/>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="返回桌面"
android:id="@+id/button4"
android:layout_weight="1"
android:onClick="bt3_onClick"/> <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="@+id/button2"
android:layout_gravity="center"
android:textSize="20sp"
android:textColor="@color/colorPrimary"
android:background="@drawable/anniu05"
android:visibility="gone"/>
</LinearLayout>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.hanqi.myapplication"> <uses-permission android:name="android.permission.CALL_PHONE"></uses-permission> <application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme"> <activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".TextActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity> </application> </manifest>

Android-activity-intent的更多相关文章
- Android总结篇系列:Activity Intent Flags及Task相关属性
同上文一样,本文主要引用自网上现有博文,并加上一些自己的理解,在此感谢原作者. 原文地址: http://blog.csdn.net/liuhe688/article/details/6761337 ...
- 【转】Android Activity和Intent机制学习笔记----不错
原文网址:http://www.cnblogs.com/feisky/archive/2010/01/16/1649081.html Activity Android中,Activity是所有程序的根 ...
- Android Activity 的四种启动模式 lunchMode 和 Intent.setFlags();singleTask的两种启动方式。
原文:Android Activity 的四种启动模式 lunchMode 和 Intent.setFlags();singleTask的两种启动方式. Android Activity 的四种启动模 ...
- Android Activity和Intent机制学习笔记
转自 http://www.cnblogs.com/feisky: Activity Android中,Activity是所有程序的根本,所有程序的流程都运行在Activity之中,Activity具 ...
- 【转】Android总结篇系列:Activity Intent Flags及Task相关属性
[转]Android总结篇系列:Activity Intent Flags及Task相关属性 同上文一样,本文主要引用自网上现有博文,并加上一些自己的理解,在此感谢原作者. 原文地址: http:// ...
- 008 Android activity实现多个界面的相互跳转(主要利用Intent)
1.activity介绍 一个activity就把他理解成一个页面 2.新建activity流程 如图所示在com.lucky.test06的目录下,右击new--->Activity---&g ...
- Android之Intent和Activity
Intent能够说是Android的灵魂,程序跳转和传递数据的时候基本上就是靠Intent了.Intent在Android应用中是相当重要的,理解Intent相应用编程非常有帮助.在Android的官 ...
- Android笔记---Intent实现Activity跳转
学了之前的Android控件以及布局,我们就能够做一些UI的设计了,这里我结合之前的知识.以一个小的登录项目来解说下Activity之间跳转. 先看下效果图: 1.登录界面: 2.点击登录按钮跳转到另 ...
- Android 笔记 Intent and Bundle day7
学习了Intent与Bundle的使用,进行应用中的交互 package com.example.intent; import android.app.Activity; import android ...
- Android Activity launchMode研究
Android Activity launchMode研究 Activity的Launch mode一共有四种: standard, singleTop, singleTask, singleInst ...
随机推荐
- 关于VS 中 HttpHandler 的设置 500.23
前一段时间在讲 HttpHandler 的过程中遇到一些问题,在此分享一下. 使用VS2012 添加HttpHandler后,在web.config配置的节点如下: <?xml version= ...
- SlidingMenu实现app侧滑功能
很多APP都有侧滑菜单的功能,部分APP左右都是侧滑菜单~SlidingMenu 这个开源项目可以很好帮助我们实现侧滑功能,如果对SlidingMenu 还不是很了解的童鞋,可以参考下本篇博客. 本片 ...
- 某硕笔试题mysql数据库部分(较为全面)
Student(S#,Sname,Sage,Ssex) 学生表 Course(C#,Cname,T#) 课程表 SC(S#,C#,score) 成绩表 Teacher(T#,Tname) 教师表 ...
- JVM 指令集
指令码 助记符 说明 0x00 nop 什么都不做 0x01 aconst_null 将null推送至栈顶 0x02 iconst_m1 将int型-1推送至栈顶 0x03 iconst_0 将int ...
- 【JQGRID DOCUMENTATION】.学习笔记.6.Editing:Common Rules
1 公共编辑属性 要在grid中显示数据的一个关键原因是能简单快速地编辑它.jgGrid提供三种编辑方式: cell editing:编辑指定cell inline editing:编辑同一行的几个c ...
- MySQL数据库的常用操作
/*创建表*/ CREATE TABLE tb_test ( id ) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增主键', name ) NOT NULL ...
- Android Studio解决unspecified on project app resolves to an APK archive which is not supported
出现该问题unspecified on project app resolves to an APK archive which is not supported as a compilation d ...
- C++中new和delete来创建和释放动态数组
在C++编程中,使用new创建数组然后用delete来释放. 一.创建并释放一维数组 #include<iostream> using namespace std; int main() ...
- c# 遍历子控件,比如Form下的group,或者panel
方法很好用.目的是遍历所有容器的子控件... 方法1private void GetControl(Control.ControlCollection ctc, ref int checkNull) ...
- 【转】MySQL5安装的图解(mysql-5.0.27-win32.zip)
转载地址:http://blog.csdn.net/xssh913913/article/details/1713182 MySQL5安装的图解(最新版) http://hi.baidu.com/yu ...