English 中文(简体)
无价值
原标题:null value in getIntent.getExtras.getString()

这是我在第一项活动中的守则:

Intent i = new Intent(this, OtherScreen.class);
    i.putExtra("id1", "first");
    i.putExtra("id2", "second");
    startActivity(i);

where first,second are the values I want to be passed. and on my other class i have this:

Intent i = getIntent();
        Bundle extras = i.getExtras();
        String result = extras.getString("id1");
        System.out.println("yeah"+result);

but after i run it, my result is null.Can you help me? If I write my getString in that ways, I am getting syntax errors.

String result = extras.getString(id1); //id1 cannot be resolved to a variable
String result = extras.getString("id1","default value"); // remove argument
最佳回答
Intent i = new Intent(yourcurrentactivity.this, OtherScreen.class);

i.putExtra("id1", "first");
i.putExtra("id2", "second");
startActivity(i);

Bundle extras = getIntent().getExtras();
if (extras != null) {
    String result = extras.getString("id1");                
    System.out.println("yeah"+result);
}
问题回答

或者为了提高准确性,你可以使用

`if(getIntent.hasExtras("id11") 

在此之前,实际上从捆绑中获取额外资金,如果拆解,则采取一些行动。

审判:

getIntent().getStringExtra("id11");

当然,如果飞行情报和安全局在你甚至到场之前就有了额外的东西,它最好检查。

参看:

我的项目也存在同样的问题。

intent.putExtra("key",editText.getText())

我已将德特Text.getText()改为Sting文本。

String text = editText.getText();
intent.putExtra("key",text);

这解决了我的问题。 Seems such as it is an AP problem.

页: 1 String results = extra.get ("id1”);

如果仍有问题,解决办法就是。

你们最初通过的数据类型在收尾时应相同。

 Intent myIntent = new Intent(D1Activity.this, D2Activity.class); 
         myIntent.putExtra("dval", dval); 
         D1Activity.this.startActivity(myIntent); 

D2 积极性

Bundle extras = getIntent().getExtras();
    if (extras != null) {;
        edval = extras.getInt ( "dval" );
    }

在这里,我们通过的不是扼杀性的“Int”不会奏效。





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签