3

I'm trying to create a shortcut for an another application's activity (which is mine too). The shortcut starts the activity correctly, but just one of the two extras is received (or sent, I don't know). See the code below:

//Setting up the intent
Intent intent = new Intent();
intent.putExtra("num", 12);
intent.putExtra("name", "something");
intent.setComponent(new ComponentName
    ("com.myanother.app","com.myanother.app.MyActivity"));

And the other activity:

Bundle extras = getIntent().getExtras();
    if (extras != null) {
        int num = extras.getInt("num"); //this worked
        String name = extras.getString("name"); //this gets null

So, what's wrong? And sorry for my English if I made some mistakes.

Jorge Moreira
  • 95
  • 2
  • 11

2 Answers2

1

Instead of trying to put in multiple extras you can try to pass a bundle as an extra. Look at the first answer of this question. The question is similar and the solution should be work.

Community
  • 1
  • 1
Ryan Smith
  • 1,628
  • 3
  • 13
  • 18
1

Try this:

Bundle bund = new Bundle();

bund.putInt("num",12);
bund.putString("name","hello world");

Intent intent = new Intent();

intent.putExtras(bund);

intent.setComponent(new ComponentName
("com.myanother.app","com.myanother.app.MyActivity"));
Umer Farooq
  • 7,356
  • 7
  • 42
  • 67