1

I have some class.

public class MainActivity extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Intent newintent = new Intent(getApplicationContext(),Main2Activity.class);
    newintent.putExtra("SOME_Data", "Perfect_Data");
    startActivity(newintent);
    finish();
}
}

I want to retrive some data in another class.

public class Main2Activity extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main2);

    Intent i = this.getIntent();
    Bundle s = getIntent().getExtras();

}
}

But when i launch this code,instead bundle with string "Perfect_Data" I get this error "Bundle[mParcelledData.dataSize=68]".

Can you help me?

2 Answers2

3

If you want to print the content of Bundle, use this:

for (String key : bundle.keySet()) {
    Object value = bundle.get(key);
    Log.d(TAG, String.format("%s %s (%s)", key,  
        value.toString(), value.getClass().getName()));
}

Otherwise it just uses the default toString() of the Object class, which is what you got.

Chau Thai
  • 704
  • 6
  • 10
0

The Bundle gets printed using the default toString function.

If you just want to get the String, change it to this:

Intent i = this.getIntent();
String data = i.getStringExtra("SOME_Data");
Francesc
  • 25,014
  • 10
  • 66
  • 84