Pass data using Intent & bundle need to convert to int

I'm trying to pass data to another activity, but after passing it I want to convert it to int is there a way to do that.

This my code:

Intent intent = getIntent();

    Bundle bundle = intent.getExtras();

    if(bundle != null) {

        checker.setText(bundle.getString("temperature"));
        String checkerHolder = checker.getText().toString();

        int finder = Intent.parseIntent(checkerHolder);

    }

The "checkerHolder" is the problem here look at the pic:

Any idea ?

Answers


replace this line

int finder = Intent.parseIntent(checkerHolder);

with below one

    int finder = Integer.parseInt(checkerHolder);

Try just int finder = Integer.parseInt(checkerHolder).


If your purpose is to get a integer at the other end, why don't you send it as an integer itself. You can do it easily as given below.

Add this in the sender activity

Bundle yourBundleName = new Bundle();

yourBundleName.putInt("yourKey", 100);
Intent yourIntentName = new Intent();
myIntent.putExtras(yourBundleName);

startActivity(yourIntentName);

On the receiving end simply get it as a Integer

Bundle extras = getIntent().getExtras(); 

if(extras !=null)
{
    int yourIntegerName = extras.getInt("yourKey");
}

This will reduce your conversion part.

If you still need it as a String and want to convert it to integer, you can use this

int yourIntegerName = Integer.parseInt(yourStringName)

Any troubles ? Feel free to ask.


Need Your Help

Remove HTML tags in AppEngine Python Env (equivalent to Ruby's Sanitize)

python google-app-engine html-sanitizing

I am looking for a python module that will help me get rid of HTML tags but keep the text values. I tried BeautifulSoup before and I couldn't figure out how to do this simple task. I tried searchin...