0

I'm building a small quiz app with 3 activities A, B, C. A startActivity() to B. B has a fragment B_frag to show the quiz detail, after finish the quiz B_frag will startActivity() to C which is the result activity. C has an option to redo the quiz which will startActivity() to B again, this time with a string through intent.putExtra(). The problem is nothing comes out of the intent.getStringExtras() on activity B after being called from C. Can someone pls tell me why this happens and how to fix it?

3 Answers3

0

From the Activity C try to use FLAG_ACTIVITY_SINGLE_TOP when you call startActivity() to start Activity B. Then in Activity B override onNewIntent() to get the new intent from Activity C.

mr.icetea
  • 2,607
  • 3
  • 24
  • 42
0

Show us some code.
For sending data from Activity A to Activity B, try this:

intent.putExtra("someKey", yourView.getText().toString());

In Activity B:

Bundle bundle = getIntent().getExtras();
if (bundle!=null){
        yourString= bundle.getString("someKey", "no name");
    }
yourView.setText(yourString);
Pang
  • 9,564
  • 146
  • 81
  • 122
Abhilash Harsole
  • 244
  • 2
  • 4
  • 15
-1

Try setting flag new task when calling startactivity from c to b.

vivek
  • 284
  • 3
  • 8
  • Setting `Intent.FLAG_ACTIVITY_NEW_TASK` is completely useless when you call `startActivity()` from one of your own activities, as the `Activity` will always be launched into the current task (unless you have explicitly set `taskAffinity` in the manifest. Also, this flag has no effect whatsoever on extras in the `Intent`. – David Wasser Oct 06 '16 at 14:43