android


popup window to appear in all the activities of the application


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);
}
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.

Related Links

Audio [MediaPlayer] is not working for my Piano Apps
how to put an array into a spinner in an alert box?
Android Notification flash lights doesn't work
Manually ending the IntentService worker thread
detect outgoing call when another call is already active android
set Keyboard coordination: How to set the keyboard x,y co ordination
how can i record audio file as .m4a format?
Android app installation not including SQLite database
android system stats in eclipse debug perspective
Adding onclick to CustomAdapter to handle onClickEvents
How to estimate power consumption of an Android app? Is it linear?
There is problem when I use timer to send data to server?
showing multiple values of an object in a row
How to get ActivityGroup to get result from child activity
Android SQLite - Update table only if different
How to update a single row of a ListView with animation?

Categories

HOME
string
cublas
simulink
dojo
cq5
title
special-characters
ibeacon-android
resultset
jsonpath
gource
do-while
altera
coin3d
keytool
connector
replication
react-toolbox
joptionpane
event-store
expressionengine3
ceylon
user-defined-functions
volatile
livelink
pdw-file-browser
searchkit
graphhopper
gdata
verifiable-c
unordered-map
doc
oim
facebook-social-plugins
magento-2.0.7
builder
serde
twilio-click-to-call
static-cast
mach-o
objectscript
taocp
mapxtreme
adafruit
jodd
boost-serialization
upx
libav
decimalformat
poppler
page.js
pax-exam
sapscript
bcache
viewer
administration
appserver
wcm
rmysql
angular-carousel
reflector
ray
draw2d-js
spring-remoting
isqlquery
merb
joomla-template
preload
sqlclr
web-notifications
pstack
sentestingkit
iboutlet
hibernateexception
update-statement
inline-formset
unattended-processing
load-time
globals

Resources

Encrypt Message