In my app sometimes I receive this error :
java.lang.IllegalArgumentException: Receiver not registered: android.widget.ViewFlipper$1@4806a4a8
at android.app.ActivityThread$PackageInfo.forgetReceiverDispatcher(ActivityThread.java:667)
at android.app.ApplicationContext.unregisterReceiver(ApplicationContext.java:840)
at android.content.ContextWrapper.unregisterReceiver(ContextWrapper.java:321)
at android.widget.ViewFlipper.onDetachedFromWindow(ViewFlipper.java:104)
at android.view.View.dispatchDetachedFromWindow(View.java:5891)
at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:1076)
at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:1074)
at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:1074)
at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:1074)
at android.view.ViewRoot.dispatchDetachedFromWindow(ViewRoot.java:1570)
at android.view.ViewRoot.doDie(ViewRoot.java:2565)
at android.view.ViewRoot.die(ViewRoot.java:2535)
at android.view.WindowManagerImpl.removeViewImmediate(WindowManagerImpl.java:218)
at android.view.Window$LocalWindowManager.removeViewImmediate(Window.java:436)
at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3498)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3599)
at android.app.ActivityThread.access$2300(ActivityThread.java:119)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1867)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4363)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:862)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)
at dalvik.system.NativeStart.main(Native Method)
What's this? What should I do? Need some help please...
Here is some code :
on onCreate()
method I have this :
vf = (ViewFlipper) findViewById(R.id.details);
vf.setFlipInterval(3000);
vf.startFlipping();
populate();
where populate method is this :
private void populate() {
for (int i = 0; i < jArray.length(); i++) {
System.out.println("lungime" + jArray.length());
LinearLayout l = new LinearLayout(this);
l.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT));
l.setBackgroundColor(0x000000);
l.setOrientation(LinearLayout.VERTICAL);
vf.addView(l);
File f = new File(Environment.getExternalStorageDirectory()
+ "/Downloads/");
File[] files = f.listFiles();
Bitmap bitmap = BitmapFactory.decodeFile(files[i].getPath());
img = new ImageView(this);
img.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT));
img.setImageBitmap(bitmap);
System.out.println("target " + target[i]);
img.setOnTouchListener(this);
img.setId(i);
l.addView(img);
img = null;
}
According to Daniel Lew's solution, create this class:
import android.content.Context;
import android.util.AttributeSet;
import android.widget.ViewFlipper;
public class GabrielleViewFlipper extends ViewFlipper {
public GabrielleViewFlipper(Context context) {
super(context);
}
public GabrielleViewFlipper(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onDetachedFromWindow() {
try {
super.onDetachedFromWindow();
}
catch (IllegalArgumentException e) {
stopFlipping();
}
}
}
and in your layout don't use the normal ViewFlipper, use GabrielleViewFlipper:
<your.package.GabrielleViewFlipper
.
.
.
</your.package.GabrielleViewFlipper>