How to transfer each instance once when using singleTask

I use unidirectional mode, which processes certain types of files, setting intent filters. I need to process each such Intent file exactly once. The problem in onNewIntent () is only called if the task is already alive, forcing me to handle the intent fromCreate () too. Unfortunately, onCreate () is called for a number of reasons (for example, screen rotation), and the Intent returned by getIntent () may be the same in several onCreate (). Of course, you can get around this with some ugly hack, but I was wondering what an elegant solution would be. So far, the best solution I've come up with is setIntent (new Intent (Intent.ACTION_MAIN)) every time after processing the intent. This is similar to how the web server redirects you to the GET page after the POST page to avoid re-operation as a result of the update.

Thanks!

+4
source share
3 answers

I'm not sure if I get your problem, but as soon as you name the intention and start a new activity, right after the call () ends; to complete the activity you are leaving. This will complete your last action and prevent multiple actions from starting at once.

Also, if you use screen rotation as a way to start actions, you can always control which one you do not want to run several times by setting some checks using the If and Else statements.

0
source

uninstall singleTask will solve your problem;
call remove singleTask, can be replaced by:

intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); 
0
source

What about setIntent (null) after processing it?

-1
source

All Articles