question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Async set fragment when app invisible

See original GitHub issue

When I receive a response from the server, I create a new fragment. If the application is minimized I get an error

io.reactivex.exceptions.OnErrorNotImplementedException: Can not perform this action after onSaveInstanceState

    public void render(LogoViewState logoViewState) {
        if (logoViewState instanceof LogoViewState.LoadingState) {
            statusView.setText("Connecting...");
        } else if (logoViewState instanceof LogoViewState.DataState) {
            statusView.setText(logoViewState.toString());
            if (getActivity() != null) {
                ((MainActivity)getActivity()).showHomeFragment();
            }
        }
    }

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:26 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
sockeqwecommented, Jul 2, 2017

Yes, i have already said in a previous comment, that lifecycle should be between onStart() and onStop() and that I will fix it soon. Thanks for providing your feedback, logs and help!

DrobyshevAlex notifications@github.com schrieb am So., 2. Juli 2017, 21:07:

I have a fregment with presenter. If i press back button for close app then fragment has destroed. But subscribers from presenter don’t dispose.

When i run application after destroy the fragment i watch in log 2 line that print from doOnNext.

D/App: test D/App: test

If a press back button again then nex run application print 3 line to log.

D/App: test D/App: test D/App: test

etc…

I create BaseFragment

public abstract class BaseFragment<V extends MvpView, P extends MviPresenter> extends MviFragment { protected P presenter; protected Unbinder unbinder = null; private boolean isAttached = true;

@Override
public void onStart() {
    super.onStart();
    if (presenter != null && !isAttached) {
        presenter.attachView(this);
    }
}

@Override
public void onStop() {
    super.onStop();
    if (presenter != null && isAttached) {
        presenter.detachView(true);
    }
}

@Override
public void onDestroy() {
    super.onDestroy();
    if (presenter != null) {
        presenter.detachView(false);
    }
    if (unbinder != null) {
        unbinder.unbind();
    }
}

}

Now everything works as it should

presenter.detachView(false); - fix it

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/sockeqwe/mosby/issues/257#issuecomment-312510708, or mute the thread https://github.com/notifications/unsubscribe-auth/AAjnrn5bq7VVyKUG0HmcbUzP_wUF6QMqks5sJ-pggaJpZM4OImad .

1reaction
sockeqwecommented, Jun 29, 2017

Yeah, currently Mosby uses onCreateView() and onDestroyView() … I might change that to solve this issue

DrobyshevAlex notifications@github.com schrieb am Do., 29. Juni 2017, 21:42:

if i can move code from FragmentPresente to ActivityPresenter app work good!

But i need some fragments with intent code… I don’t want make some activites 😃

Can you help me please?

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/sockeqwe/mosby/issues/257#issuecomment-312082432, or mute the thread https://github.com/notifications/unsubscribe-auth/AAjnrtvIwuiIZv4-XD7DDKvBl3WqaWUYks5sI_48gaJpZM4OImad .

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is it possible to make a fragment transaction in background? If ...
Suppose the application is background, the async task is running every 4 secs and if I get 'Cancelled' while the app is still...
Read more >
Fragment lifecycle - Android Developers
The onAttach() callback is invoked when the fragment has been added to a FragmentManager and is attached to its host activity.
Read more >
FragmentTransaction.hide()- findings | by Nav Singh - Medium
What happens when we call hide on any fragment transaction : It hides an existing fragment. It will cause the view to be...
Read more >
Building dynamic user interfaces in Android with fragments
To define a new fragment you either extend the android.app. ... Fragment becomes not visible. ... Adding fragments statically to the layout file....
Read more >
Async Fragments: Rediscovering Progressive HTML ...
At eBay, we take site speed very seriously and are always looking for ways to allow developers to create faster-loading web apps.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found