0

I'm writing an application that has several activities. The main activity can receive data via Intent, then start another activity that process that data.

I have a problem when finished the second activity, since the main activity runs the onResume method (where check and intentions of the process), and the original intention is still alive. So App calls the second activity again.

My question is to eliminate the Intent data after calling second activity, and thus the return of second intention not to repeat the cycle.

Thank you very much

MLProgrammer-CiM
  • 17,231
  • 5
  • 42
  • 75
Pibs
  • 13
  • 5

4 Answers4

0

set a class variable to 0 and then make it 1 instead. So you don't do the looping.

Joshua Byer
  • 524
  • 4
  • 11
0

Can I eliminate the Intent data after calling second activity

yes.

As soon as you call second activity(Or the second activity is started), first activity onPause method will be called. You can override onPause method in Activity1 and do what ever you like to do.

Ex:

@Override
protected void onPause() {
    super.onPause();
    getIntent().removeExtra("YourMainActivityData");
}
Sai Phani
  • 462
  • 3
  • 6
  • That's not a meaningful answer until you suggest something to do in onPause() which will solve the problem. – Chris Stratton Apr 13 '15 at 00:05
  • @ChrisStratton Then I should say, that's not meaningful question. If you don't provide any code, I assume that you can handle coding part if you know how to do it. If you want proper solution with coding, update your question with some details of main activity intent data and how you are handling that data. – Sai Phani Apr 13 '15 at 01:56
  • @ChrisStratton sorry,I thought you were the person who asked the question. Anyhow I updated my answer with code. In fact question is not proper. If I give random code, it will misguide readers. – Sai Phani Apr 13 '15 at 02:03
0

Try add this code after u start second activity in onResume:

setIntent(new Intent());

this will replace the return intent when u call getIntent();

Hope it helps.

Euporie
  • 1,896
  • 1
  • 21
  • 23
  • I tried this. Thank you very much. I got a nullPointerException error, so I add `if (intent!=null)`. With this solution, the second time I click a link, the app don't call its second activity, stay at Main activity. The new Intent is missing, I don't understand it – Pibs Apr 14 '15 at 00:43
0

I can't remove Intent data, so I wrote an alternative method. I did set the intent-filter at the second activity, and this activity does all the work. When user wants to go back, I start first activity and finih second one.

Perhaps it's a good method, perhaps not is. But it runs OK for me.

Thank you very much!

Pibs
  • 13
  • 5