I have an activity (say A) which is launched in singleTask mode. I created a popup in this activity and added it to the parent view of activity A. Now I launched Activity A from somewhere else and I receive onNewIntent() call, where I reinitialize the new view. But how do I destroy this popup before I reinitialize A?
Here is my code : This is how I created popup.
final ViewGroup rootView = (ViewGroup) getWindow().getDecorView().getRootView();
RelativeLayout popup = (RelativeLayout) LayoutInflater.from(this).inflate(R.layout.popup_r,null);
popupView = popup;
rootView.addView(popup);
Here is my onNewIntent method
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
if (popupView != null)
{
((ViewGroup)popupView.getParent()).removeView(popupView);
popupView = null;
}
setIntent(intent);
setContentView(R.layout.activity_view);
reinitView();
}
But this gives me crash, here is the logcat:
java.lang.NullPointerException: Attempt to write to field 'android.view.ViewParent android.view.View.mParent' on a null object reference
at line ((ViewGroup)popupView.getParent()).removeView(popupView);
How do I remove popupview before reinitializing activity with new intent?