Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clear arguments in Fragment?

I have an AudioPlayerFragment to which I pass some url with setArguments().

If I have an url key in the getArguments() of my instance of AudioPlayerFragment, I start a service that plays the audio stream. If there was already a stream playing, I stop it and start it again with the new stream.

If there is no arguments, I do nothing.

My problem is that the arguments are kept with the instance, so when I get back to it, getArguments() returns the latest arguments set, if no new have been set.

So after reading them, I try to set the arguments to null with

setArguments(null);

But I get

Java.lang.IllegalStateException: fragment already active

How can I clear the arguments then?

like image 832
jul Avatar asked Jul 26 '13 07:07

jul


1 Answers

Call this.getArguments().clear(); in onDestroyView() method in your fragment.

like image 125
Balflear Avatar answered Sep 28 '22 05:09

Balflear