Skip to content
This repository has been archived by the owner on Jan 14, 2018. It is now read-only.

SpiceManager : Could not unbind from service #96

Closed
mcastets opened this issue May 14, 2013 · 15 comments
Closed

SpiceManager : Could not unbind from service #96

mcastets opened this issue May 14, 2013 · 15 comments
Assignees
Milestone

Comments

@mcastets
Copy link

Hi guys,

I sometimes get this error:

java.lang.IllegalArgumentException: connection is null

The detailed logcat:

spicemanager

I only use the spiceManager.start() and the spiceManager.shouldStod() within Fragments.

Any ideas where does it come from or why does this happen?

@stephanenicolas
Copy link
Owner

Hello Bobby,

this bug seems to be related to this : http://stackoverflow.com/q/7581986/693752.
The support library that is available on maven central is release 7, the latest is release 12 and may correct that bug.

Can you do the following to see if it solves the bug :

@Override
public void onStop() {
    if( spiceManager.isStarted() ) {
       spiceManager.shouldStop();
    }
}

If so, I will update the samples and documentation of RS.

Thanks for your interest in RoboSpice.
S.

@ghost ghost assigned stephanenicolas May 15, 2013
@mcastets
Copy link
Author

Thanks for the quick reply.

Unfortunately adding the isStarted() condition didn't resolve the issue.

In addition, I am not using the support library but only android.app.Fragment as I run my app only on > 4.0 devices.

Here is a simple test case :

  • Launching app, a new activity is created and a fragment is attached. SpiceManager is started:

testcase1

  • Orientation changed. I do believe something weird is happening here: look at the exception. And why do I have two "Bound to service : UbiSpiceService"?

testcase2

  • Back button is hit, leaving the app. The exception SpiceManager : Could not unbind from service is raised.

testcase3

I hope it helps.

@stephanenicolas
Copy link
Owner

Yes it does, definitely. It looks like the fragment is started and stopped very quickly at 10.18.15:936 and the binding occurs after the unbinding. Then a new binding occurs 10.18.16.025 and results in this and the previous binding to be successful.

This cycle happens again on back button and that fails dramatically the second time.

Do you use a fragment inflated from XML or created by code ? If the latter case, would you mind to post your fragment related code and its location in the activity ?

Stéphane

@mcastets
Copy link
Author

Hello Stephane,

First of all, I would like to apologize for the late answer but I was a bit away from work :-)

Finally, I found where does this issue come from... And I am quite embarrassed because the problem was totally related to my fragments lifecycle and not to RS.

Indeed, on orientation change I misunderstood how Android worked and I was recreating my fragments whereas Android was already taking care of it. That's explained why everything was duplicated...

So, thanks for shedding some light on my issue and I feel deeply sorry for the inconvenience this has caused you.

@mcastets
Copy link
Author

Finally, I'm back again because with a proper implementation of fragments, I still hit the bug and I can happily say that adding:

@Override
public void onStop() {
    if( spiceManager.isStarted() ) {
       spiceManager.shouldStop();
    }
}

Is the perfect solution :-)

So now I'm feeling less stupid compared to my previous post.

@stephanenicolas
Copy link
Owner

Hi again Bobby-Jackson,

thx a lot for all the feedback on this issue. I just updated the fragment
sample for RoboSpice so that RS users can have a better reference on RS
usage with fragments.

Again, this bug is related to a bad fragment life cycle inside Support
library r7. The bug seems to have been solved with r12, but unfortunately,
it ain't available on maven central yet. Let's hope that graddle support in
android will motivate Google Androiders to update their artifact more often.

As a complement, if people want to use r12 in their project then they can :

  • use maven sdk deployer and get their local support jar deployed in
    their local maven repo / local nexus.
  • add an exclusion to robospice dependency, excluding support
  • adding back their local support lib (that will a different groupId /
    artifcatId)

That should definitely solve this "bug" in RS until Support r12+ is
available on central.

Stéphane

@stephanenicolas
Copy link
Owner

Fragment sample and start guide have been updated to reflect this issue.

dpsm pushed a commit to dpsm/robospice that referenced this issue May 27, 2013
@StingerAJ
Copy link

Why don't you move the if-clause into the shouldStop-method to save the RS-users some trouble?
Nevertheless, I don't know why, but I accidentally included this if-clause at some point myself after getting this bug.

@stephanenicolas
Copy link
Owner

I agree that it would save trouble. Nevertheless, this is a support bug.
There are others and I don't wanna add code to RS to patch some deficiency
of an absolete version of support.

Stéphane

2013/6/14 StingerAJ [email protected]

Why don't you move the if-clause into the shouldStop-method to save the
RS-users some trouble?
Nevertheless, I don't know why, but I accidentally included this if-clause
at some point myself after getting this bug.


Reply to this email directly or view it on GitHubhttps://github.com//issues/96#issuecomment-19453917
.

Stéphane NICOLAS,
OCTO Technology
Développeur & Consultant Android / Java
..........................................................
50, Avenue des Champs-Elysées
75008 Paris
+33 (0)6.26.32.34.09
www.octo.com - blog.octo.com
www.usievents.com
...........................................................

@kjsolo
Copy link

kjsolo commented Dec 3, 2013

I am sorry, this bug still exists.

I already use the code in Fragment:

@Override
public void onStop() {
    if( spiceManager.isStarted() ) {
       spiceManager.shouldStop();
    }
}

Here is my code, initialize Fragment in Activity:

SpiceManager in MainFragment

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);

        FragmentManager fm = getSupportFragmentManager();
        FragmentTransaction ft = fm.beginTransaction();
        if (fm.findFragmentById(R.id.content_frame) == null) {
            contentFragment = MainFragment.newInstance();
            ft.add(R.id.content_frame, contentFragment);
        }

        // configure the SlidingMenu
        menu = new SlidingMenu(this);
        menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN);
        menu.setShadowWidthRes(R.dimen.shadow_width);
        menu.setShadowDrawable(R.drawable.shadow);
        menu.setBehindOffsetRes(R.dimen.slidingmenu_offset);
        menu.setFadeDegree(0.35f);
        menu.attachToActivity(this, SlidingMenu.SLIDING_WINDOW);
        menu.setMenu(R.layout.menu_frame);

        if (fm.findFragmentById(R.id.menu_frame) == null) {
            ft.add(R.id.menu_frame, new SlidingMenuFragment());
        }
        ft.commit();
    }

But sometimes throw Could not unbind from service exception.

How to use it correctly in Fragment or other way (like start on Activity, not in Fragment)?

I apologize my english.

@doridori
Copy link

doridori commented Jan 7, 2014

Your not calling super.onStop()

@stephanenicolas
Copy link
Owner

@kjsolo Which version of RS are you using, it looks like this bug has been patched a while ago.

@DarthWendigo
Copy link

I have the same problem, what's the last version? I want to update my build.gradle. Actually my version is 1.4.8.

compile('com.octo.android.robospice:robospice-retrofit:1.4.8')

Thanks in advance.

The wiki says this:
compile ('com.octo.android.robospice:robospice-spring-android:1.4.7')

@rciovati
Copy link
Contributor

@DarthWendigo latest version is 1.4.11

@DarthWendigo
Copy link

@rciovati thanks! 👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants