Android的意图束总是空? [英] Android intent bundle always null?

查看:89
本文介绍了Android的意图束总是空?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我运行下面的code。有两个片段。第一个是我如何设置包和第二我如何取回它。出于某种原因,我每次检查它返回的空包。

这是为什么这是或我做错了会大大AP preciated。任何意见

 意向意图=新的意图(这一点,com.hom.app.Hom.class);
        叠B =新包();
        b.putString(好,是);
        intent.putExtras(B);
    startActivity(意向);
 

检索软件包:

 字符串以及=;
    捆绑包子= getIntent()getExtras()。
    字符串标准=是;
    如果(包子!= NULL){
        Log.v(捆绑,包含数据);
        还有= bun.getString(井);
        如果(井== NULL)以及=;
        如果(井==标准)法();
    }
 

解决方案

在你创建你的意图,只是把临时演员就在那里。您试图访问错误的包在code以上。这样的事情应该工作。

 意向意图=新的意图(这一点,com.hom.app.Hom.class);
    intent.putExtras(好,是);
    startActivity(意向);
 

I am running the below code. There are two snippets. The first is how I am setting the bundle and the second how I am retrieving it. For some reason every time i check the bundle it returns as null.

Any advice on why this is or what I have done wrong would be greatly appreciated.

    Intent intent = new Intent(this, com.hom.app.Hom.class);
        Bundle b = new Bundle();
        b.putString("WELL", "yes");
        intent.putExtras(b);
    startActivity(intent);

Retrieving Bundle:

    String well ="";
    Bundle bun = getIntent().getExtras();
    String standard = "yes";
    if(bun != null){       
        Log.v("Bundle", "Contains data");
        well = bun.getString("WELL");
        if(well == null) well = "";
        if(well == standard) method();
    }   

解决方案

When you are creating your intent, just put the extras right in there. you are trying to access the wrong bundle in your code above. Something like this should work.

    Intent intent = new Intent(this, com.hom.app.Hom.class);
    intent.putExtras("WELL", "yes");
    startActivity(intent);

这篇关于Android的意图束总是空?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆