android之无返回结果跳转intent:
(注意跳转的时候要传像user的对象必须实现Serializable接口)
登陆页面布局:layout/activity_login.xml:
<LinearLayout 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:orientation="vertical">
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:stretchColumns="1" >
<TableRow
>
<TextView
android:text="输入编号:"/>
<EditText
android:id="@+id/etUser"
android:hint="请输入1-10个字符"/>
</TableRow>
<TableRow >
<TextView
android:text="密码:"/>
<EditText
android:id="@+id/etPassw"
android:hint="请输入1-10个字符"
android:password="true"/>
</TableRow>
</TableLayout>
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<TableRow >
<Button
android:visibility="invisible"
/>
<Button
android:id="@+id/register"
android:text="登陆"
android:drawableLeft="@drawable/login32x32"
android:background="@drawable/btn_bg"/>
<Button
android:visibility="invisible"
/>
<Button
android:id="@+id/exit"
android:drawableLeft="@drawable/exit32x32"
android:background="@drawable/btn_bg"
android:text="退出"/>
<Button
android:visibility="invisible"
/>
</TableRow>
</TableLayout>
</LinearLayout>
登陆页面java程序:
package com.example.day04_01;
import android.support.v7.app.ActionBarActivity;
import android.test.UiThreadTest;
import android.text.TextUtils;
import android.content.Intent;
import android.os.Bundle;
import android.os.SystemClock;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
public class LoginActivity extends ActionBarActivity {
private EditText etUser,etPassw;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
init();
setListener();
}
private void setListener() {
// TODO Auto-generated method stub
findViewById(R.id.register).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
// TODO Auto-generated method stub
String code = etUser.getText().toString();
if(TextUtils.isEmpty(code)){
etUser.setError("编号不能为空");
return;
}
String passw = etPassw.getText().toString();
if(TextUtils.isEmpty(passw)){
etPassw.setError("密码不能为空");
return;
}
Intent intent = new Intent(LoginActivity.this,MainActivity.class);
intent.putExtra("code", code);
intent.putExtra("password", passw);
User user = new User(code,passw);
intent.putExtra("user", user);
startActivity(intent);
}
});
findViewById(R.id.exit).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
// TODO Auto-generated method stub
finish();
}
});
}
private void init() {
// TODO Auto-generated method stub
etUser = (EditText) findViewById(R.id.etUser);
etPassw= (EditText) findViewById(R.id.etPassw);
}
}
跳转页面布局:layout/activity_main.xml:
<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="com.example.day04_01.MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
</RelativeLayout>
跳转java代码:
package com.example.day04_01;
import android.support.v7.app.ActionBarActivity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent intent = getIntent();
String code = intent.getStringExtra("code");
String passw = intent.getStringExtra("password");
User user = (User) intent.getSerializableExtra("user");
Log.i("main", "注册信息:"+user);
Toast.makeText(this,"注册信息:"+user, 2000).show();
}
}
效果:
相关推荐
什么是Intent Intent可以理解为信使(意图) 由Intent来协助完成Android各个组件之间的通讯 Intent实现页面之间的跳转 ...第二种启动方式可以返回结果 代码 FirstActivity.java public class FirstActiv
Intent跳转传值,和Activity返回传值
Android中界面间两种跳转方式startActivity(intent); startActivityForResult(intent, 0);
Android7.0 Intent打开文件管理器 获取文件真实路径。虽然网上很多demo,但是没有一个能够兼容所有Android机的,去网上学习了然后自己亲测过手机分别有Android7.0/6.0/4.3个版本。
一般在Activity页面跳转之间有两种方式,一种是直接通过startActivity的方式跳转,不会返回数据;另一种是通过startActivityForResult的方式跳转到另一个页面,也会接收从另一个页面传递回来的数据。这个项目主要是...
这时候要展示通知,点击通知栏打开App并跳转到目标页面,关闭目标页面后需要返回到应用首页,而不是直接推出App 实现思路 App在前台时,弹出Dialog提醒用户有新消息,但是最新版的个推文档接收推送消息是继承...
要求:页面1跳转到页面2,页面2再返回页面1同时返回数据 页面1添加如下代码: Intent intent = new Intent(); intent.setClass(页面1.this, 页面2.class); Bundle bundle = new Bundle(); intent.putExtras(bundle)...
在上一篇文章中我介绍了使用Intent显式来实现页面向下跳转,接下来这篇文章主要介绍的是使用Intent隐式来实现向上跳转,什么意思呢,就是当我们从第一个页面跳转到第二个页面的时候我们可以从第二个页面跳转回去. ...
使用Android Studio作为开发平台,讲述了Intent的显示跳转和隐式跳转,并有参数返回的情况。
本文实例为大家分享了Intent实现页面跳转的两种的方法,供大家参考,具体内容如下 下图中两个不同的方法就是两种页面之间跳转的情况 1).跳转不返回数据 2).跳转返回数据 实例: 第一种启动方式(跳转不返回数据) ...
Android4.0入门之Activity返回参数: 开发流程梳理: 1.对界面进行布局(在layout目录下配置每个Activity对应的xml) 2.书写Activity类,获取控件、添加时间(新增Activity后,切记到配置Activity文件中去注册) ...
Android Activity的跳转与传值详解 Activity跳转与传值,主要是通过Intent...Activity跳转,无返回结果 这是最简单的Activity跳转方式。从一个Activity启动另一个Activity,直接startActivity(new Intent(当前Activi
Intent是Android程序中各组件之间进行交互的一种重要方式,它不仅指明当前组件想要执行的动作,还可以在不同组件之间传递数据。启动活动就可以用Intent。Intent可以分成两种:显示Intent和隐式Intent。当知道要跳转...
些朋友可能对Android系统的手机不太熟悉,相信你见了Android系统的手机后你肯定会喜欢上的,绚丽的界面,好看的字体,彰显华贵和专业。本源码收集的就是android系统中的一些基本单元,比如弹出的提示框、提示层的...
Intent方法进行页面跳转适用于两个Activity之间的跳转,按返回键可以直接返回到前一个页面。 使用时需要注意在Manifest.xml文件中注册Activity activity_main.xml(Mainactivity布局) 创建按钮的onclick方法 ...
使用android.provider.MediaStore类定义的意图ACTION_IMAGE_CAPTURE。... Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(intent, R.string.exti);
这个时候,我们可以通过startActivityForResult(Intent, int)方法启动新的Activity,新的Activity通过setResult(int, Intent)方法返回老的Activity,这个时候会触发老的Activity的onActivityResult(int, int, Intent...
2 设置入口activity的启动模式android:launchMode="singleTask",重写onNewIntent方法, 在退出activity时,设置intent.setAction("exit_app");然后跳转到栈底activity, 这样就可以清除栈底之外的所有activity,...
9.3.2 跳转与返回 192 9.3.3 任务与标志 196 9.4 Android系统内置Intent 199 本章小结 201 第10章 数据存储 203 10.1 健康助手案例 203 10.2 Android数据存储概述 205 10.3 本地文件 205 10.3.1 访问SD卡 ...
添加本地图片和调用系统拍照图片主要是通过调用acitivity跳转startActivityForResult Intent intent int requestCode 方法和activity返回结果onActivityResult int requestCode int resultCode Intent data 方法来...