android intent 跳转

一、不需要返回值的跳转

Intent intent=new Intent();

intent.setClass(目前的acitivy.this, 目标activity.class);

startActivity(intent);

二、需要返回值的跳转

Intent intent=new Intent();

intent.setClass(目前的acitivy.this, 目标activity.class);

startActivity(intent);

startActivityForResult(intent, 状态值(int类型));

状态值作为接受目标返回值的验证。

requestCode 接收返回的状态值

resultCode :RESULT_OK  RESULT_CANCELED 可以自己赋值,按返回键时,系统默认赋值为:RESULT_CANCELED

目标activity 关闭才能返回请求activity

例如:

1、请求页面

public class MainActivy extends Activity {
   
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Intent intent=new Intent();
        intent.setClass(MainActivy.this, ReceiveMSG.class);
        startActivityForResult(intent, 0);      
    }

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        // TODO Auto-generated method stub
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode==0) {
            if (resultCode==RESULT_OK) {
                Toast.makeText(this, "Send SMS RESULT_OK", Toast.LENGTH_SHORT).show();
            }else if (resultCode==RESULT_CANCELED) {
                Toast.makeText(this, "result cancel", Toast.LENGTH_SHORT).show();
            }else {
                Toast.makeText(this, resultCode, Toast.LENGTH_SHORT).show();
            }
        }else {
            Toast.makeText(this, "requsetcode not 0", Toast.LENGTH_SHORT).show();
        }
       
    }
}

2、接收返回值界面

public class ReceiveMSG extends Activity{

protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);        
        ReceiveMSG.this.setResult(RESULT_OK);
        this.finish();       
    }
}

android intent 跳转,布布扣,bubuko.com

时间: 2024-12-22 20:42:41

android intent 跳转的相关文章

[android]Intent跳转新的Activity可以传递数据过去

通过intent.putExra()来传递数据 新的Activity通过 Intent intent = getInten(); 例如 //Item单击事件,单击后跳转到新的Activyty,并显示完整的内容 public void onItemClick(AdapterView<?> parent, View view, int position, long id) { //获取当前Item的完整数据 Blog bg = blogList.get(position); String tile

Android搞事篇——使用Intent跳转界面

跳转页面基本分为三个步骤: 1.初始化一个intent:(一个intent就够用了): 2.传入intent参数: 3.调用startactivity();实现跳转页面 具体操作如下 首先你需要一个项目或demo,然后就可以开始了 先在第一个布局里放一个Button;(别问我他是干嘛的)给他加一个id 然后创建一个新布局: 右键layout跳出来的菜单中有我这里给他的名字是second 然后新建一个second.java继承Activity在这个里面重写OnCreat()方法,然后将他跟布局绑定

Android开发之Intent跳转到系统应用中的拨号界面、联系人界面、短信界面

现在开发中的功能需要直接跳转到拨号.联系人.短信界面等等,查找了很多资料,自己整理了一下.1.跳转到拨号界面,代码如下: 1)直接拨打 Intent intentPhone = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + phoneNumber)); startActivity(intentPhone); 2)跳转到拨号界面 Intent intent = newIntent(Intent.ACTION_DIAL,Uri.pars

android:跳转,Intent,有无返回值

2014-08-17 <!-- 第一个页面 --> <TextView android:id="@+id/textView1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop=&

Android Intent实现页面之间跳转

什么是IntentIntent可以理解为信使(意图)由Intent来协助完成Android各个组件之间的通讯Intent实现页面逐渐的跳转1.startActivity(inetnt)2.startActivityForResult(intent, requestCode); onAcitivtyResult(int requestCode, int resultCode, Intent data) setResult(resultCode, data); 先创建两个xml文件firstacti

Android开发中使用Intent跳转到系统应用中的拨号界面、联系人界面、短信界面

现在开发中的功能需要直接跳转到拨号.联系人.短信界面等等,查找了很多资料,自己整理了一下. 首先,我们先看拨号界面,代码如下: Intent intent =new Intent(); intent.setAction("android.intent.action.CALL_BUTTON"); startActivity(intent); 和 Uri uri = Uri.parse("tel:xxxxxx"); Intent intent = new Intent(

[Android]Intent 实现页面跳转的方式[转]

第一种方式,用action来跳转. 1.使用Action跳转,如果有一个程序的 AndroidManifest.xml中的某一个Activity的IntentFilter段中定义了包含了相同的Action那么这个Intent 就与这个目标Action匹配.如果这个IntentFilter段中没有定义 Type,Category,那么这个 Activity就匹配了.但是如果手机中有两个以上的程序匹配,那么就会弹出一个对话可框来提示说明. Action的值在Android中有很多预定义,如果你想直接

android之android.intent.category.DEFAULT的用途和使用

转载(http://blog.csdn.net/jason0539/article/details/10049899) 1.要弄清楚这个问题,首先需要弄明白什么是implicit(隐藏) intent什么是explicit(明确) intent. Explicit Intent明确的指定了要启动的Acitivity ,比如以下Java代码: Intent intent= new Intent(this, B.class): Implicit Intent没有明确的指定要启动哪个Activity

Android Intent 意图作用

Intent分为两大类: (1)显性的(Explicit) (2)隐性的(Implicit) 对于隐性意图,在某些时候, 应用程序只是想启动具有某种特征的组件, 并不想和某个特定的组件耦合. 使用Intent可以方便的达到这种高层次解耦的目的.(在模块间的组件启动) intent定位事件的目的地: (1)种类(category),比如我们常见的 LAUNCHER_CATEGORY 就是表示这是一类应用程序. (2)类型(type),在前面的例子中没用过,表示数据的类型,这是隐性Intent定位目