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();
}
}
效果:
相关推荐
前者用于无返回结果的跳转,后者用于需要接收返回结果的跳转。 ```java // 显式Intent context.startActivity(intent); // 隐式Intent if (intent.resolveActivity(getPackageManager()) != null) { start...
本篇文章将深入讲解如何使用Intent在Android应用中跳转到这些地图应用,并在用户未安装相应地图应用时提供备选方案,如打开网页版地图。 首先,我们需要了解Intent的基本结构。Intent通常由两部分组成:Action和...
在Android应用开发中,Intent是连接应用程序组件的重要桥梁,它被用来启动新的Activity或Service,也可以传递数据。本文将深入探讨如何在两个Activity之间通过Intent进行数据传递。 首先,理解Intent的基本概念。...
什么是Intent Intent可以理解为信使(意图) 由Intent来协助完成Android各个组件之间的通讯 Intent实现页面之间的跳转 ...第二种启动方式可以返回结果 代码 FirstActivity.java public class FirstActiv
本教程将详细讲解如何通过Intent实现带返回值的Activity跳转,这对于Android开发者来说是非常基础且重要的技能。 一、Intent的基本概念 Intent是一种运行时的请求,用于表示应用中的一个动作,它可以携带数据。...
Intent跳转传值,和Activity返回传值
或者,如果需要在返回结果后继续执行,可以使用`startActivityForResult()`。 5. **处理权限** 跳转到其他应用可能需要请求相应的权限。例如,如果要打开浏览器,需要在AndroidManifest.xml中声明`...
总结来说,`startActivity(Intent)`适合简单的Activity跳转,无需返回结果;而`startActivityForResult(Intent, int)`则适用于需要从新Activity获取结果的场景。了解并熟练掌握这两种方法,对进行Android应用的界面...
可以使用模拟器或真实设备进行跳转测试,确保在各种情况下都能正确跳转并处理返回结果。 10. **代码示例**: 创建Intent的基本步骤如下: ```java Intent intent = new Intent(); intent.setComponent(new ...
总结来说,Android中的Activity跳转是通过Intent进行的,可以显式或隐式启动,传递数据,选择不同的启动模式,同时还需要理解Activity的生命周期和返回栈管理,以便构建高效、用户体验良好的应用。在实际开发中,应...
Activity 跳转可以分为两种:无返回结果和返回结果。 无返回结果的 Activity 跳转是通过 `startActivity()` 方法来实现的,例如: ```java startActivity(new Intent(MainActivity.this, NewActivity.class)); ```...
Android 系统广播大全 Intent 跳转界面 Android 系统广播大全 Intent 跳转界面是一种机制,允许应用程序之间进行交互和通信。Intent 是 Android 中的一种机制,可以将动作和数据封装起来,用于启动 Activity、服务...
首先,我们来看直接跳转,也称为无结果跳转。在Android中,你可以使用`startActivity()`方法启动一个新的Activity。以下是一个简单的示例: ```java Intent intent = new Intent(this, TargetActivity.class); ...
在实际开发中,你可能需要考虑更多的细节,例如处理返回结果、设置动画效果、处理Activity之间的通信等。在URLTest这个示例项目中,你可以进一步探索这些概念,加深对Android页面跳转机制的理解。
以上就是关于Android两个App之间跳转的知识点,涉及Intent、Intent Filter、数据传递和权限管理等方面。通过Android Studio,开发者可以轻松实现不同应用间的交互,提升用户体验。在实际开发中,还需要考虑安全性和...
在Android应用开发中,Intent是连接各个组件的重要桥梁,它用于启动其他Activity、Service或BroadcastReceiver,甚至可以启动意图过滤器。在这个简单的示例中,我们关注的是如何使用Intent进行页面间的跳转,而不...
此外,Android提供了多种跳转方式,如使用`startActivityForResult()`来进行有结果返回的跳转,或者使用`Intent.FLAG_ACTIVITY_CLEAR_TOP`清除栈顶的Activity等。了解这些特性可以帮助开发者更好地控制应用的导航...
首先,页面跳转在Android中主要通过Intent对象来实现。Intent是一种用来表达应用程序之间意图的类,可以理解为一个消息对象,它告诉系统你要执行什么操作。在实现页面跳转时,我们通常创建一个新的Intent实例,并...
本教程将详细介绍如何在Android Studio中实现一个功能,即通过多个按钮跳转到多个不同的页面,并利用选项卡功能来增强用户体验。首先,我们需要理解Android Studio中的布局设计、按钮事件监听以及选项卡控件的使用。...
5. **处理返回结果**:如果需要在新启动的Activity执行完后返回结果,可以使用`startActivityForResult(Intent, requestCode)`,并在新Activity中调用`setResult()`设置结果,最后在原Activity覆盖的`...