Why do intentional cleansing data accidentally return, why?

I have a multimedia application that starts playback when an intention is sent to a player’s action with the following additional intentions; "path to music" and enter "mime / audio format".

I collect the intent data in the player’s action to start playback, and I delete past additions from the intent to avoid repeating the same request after switching the screen or activity that is returned to the foreground.

This is how I handle the intent:

final String data = getIntent().getDataString(); final String type = getIntent().getType(); // start playback requestPlay( data, type ); // remove intents because they are needed only once per call! this.getIntent().setDataAndType(Uri.parse(""), ""); this.getIntent().removeExtra("data"); this.getIntent().removeExtra("type"); 

The problem that I am facing is that randomly and rarely, I will open the application, and when it resumes in the player’s activity, the intention will contain the previous additional data and start playing ... It annoys me and my users are good .. .

Does anyone have any idea what is the best way to clear intents data? For some reason, an ActivityManager can store this data ...?

Thanks!

-Jona

+8
android
source share
4 answers

My decision:

 Bundle mExtrass = null; getIntent().replaceExtras(mExtrass); 

And this is superfluous data.

+4
source share

Unclear, but have you tried the flags Intent FLAG_ACTIVITY_RESET_TASK_IF_NEEDED, FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET or FLAG_ACTIVITY_NEW_TASK?

0
source share

When extracting rows of data and types, try passing them as additional functions instead of getDataString() and getType() :

 final String data = getIntent().getExtras().getString("music_path"); final String type = getIntent().getExtras().getString("data_type"); // start playback requestPlay( data, type ); // remove intents because they are needed only once per call! this.getIntent().setDataAndType(data, type); this.getIntent().removeExtra("music_path"); this.getIntent().removeExtra("data_type"); 

Before that, you need to pass types as additional functions:

 intent.putExtra("music_path", <path to music>); intent.putExtra("data_type", <mime/audio format); 
0
source share

I got the same problem. In my case, the problem was that I sometimes got two intentions when starting the application: one in onCreate, and then the other in onNewIntent. The onCreate intent had some really old data attached (which should have been cleared according to the docs), while onNewIntent had no extra data (right case).

My solution was to write down the last incoming intent (assuming the last intent is correct) and then process the intent in onResume, since this method is called after onCreate and onNewIntent. Like this:

 private Intent lastIntent; public void onCreate() { lastIntent = getIntent(); } public void onNewIntent(Intent intent) { lastIntent = intent; } public void onResume() { if (lastIntent != null) { // handle lastIntent and then set it to null lastIntent = null; } } 
0
source share

All Articles