The removeConnectionView method is being called from a thread that isn't the main Looper thread (or, the "UI Thread"). View can only be modified from the main looper thread.
In order to fix this, instantiate a Handler sometime on the main Looper thread (such as when the view or Activity is created), and use the Hander#post(Runnable)
method to call your method, or use the View#post(Runnable)
method on your FrameLayout.
Example of the first kind:
Put this in the onCreate method of the Activity, which always runs in the main Looper thread.
mHandler = new Handler();
Then, when you want to run that method:
handler.post(new Runnable() {
@Override
public void run() {
mFrameLayout.removeView(mSpheroConnectionView);
mSpheroConnectionView = null;
}
});
Example of the second kind:
mFrameLayout.post(new Runnable() {
@Override
public void run() {
mFrameLayout.removeView(mSpheroConnectionView);
mSpheroConnectionView = null;
}
})