Reputation: 177
I am creating a popup window in AsyncTask in onPostExecute().It is showing perfectly when i am on the same activity but if I am on the other activity, It doesn't show and the app crashes. I want to make the popup window to appear on whichever activity the user currently is.
As, the layoutinflater has the basecontext of only one activity, that's why it is not showing on other activities. How can I show it on other activities as well.
Here is my popup window code:
protected void onPostExecute(Integer progress) {
View popupView = layoutinflater.inflate(R.layout.popup_window, null);
final PopupWindow popupWindow = new PopupWindow(
popupView,
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
ImageView btnDismiss = (ImageView) popupView.findViewById(R.id.imageView3);
ImageView btnDismiss2 = (ImageView) popupView.findViewById(R.id.imageView4);
ImageView btnDismiss3 = (ImageView) popupView.findViewById(R.id.imageView5);
btnDismiss.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
popupWindow.dismiss();
}
});
btnDismiss2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
popupWindow.dismiss();
}
});
btnDismiss3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
// File downloaddirectory = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES), "Youtube Videos");
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
Uri uri = Uri.parse(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES).getPath()
+ "/XYZ/");
intent.setData(uri);
GlobalDownload.context.startActivity(Intent.createChooser(DownloadScreen.intent, "Open folder"));
}
});
popupWindow.showAtLocation(popupView, Gravity.CENTER, 0, 0);
}
Upvotes: 3
Views: 1521
Reputation: 16364
AFAIK, it is not possible to share a Popup across all the Activities in your application, as it is attached to the context of the Activity which shows it. One option would to take permission to draw on the window and have a service running constantly, which draws the popup UI over your activities. But, I won't really suggest that.
A cleaner approach would be to use multiple Fragments instead of multiple Activities. Have one single Activity which hosts all the Fragments. Display the Popup with the context of the Activity and you would be able to show it across all your Fragments.
Upvotes: 3