I have an application which runs background service which checks notifications which it gets from some server. And when the notification arrives (Ping notification), it opens a new Notification dialog with full screen inflated view. On this screen you have an option to accept the call, which calls another device with SIP voice connection. This accept call opens up a new dialog fragment, which has the ability to automatically answer the call, and the user has the option to cancel it. When I am on main activity window, this works just fine. In service there is view inflated with layout added to window_manager which shows notification and when you accept the call, dialog fragment with call status opens. The question I have now, is it possible to do that while application is minimized?
So for example, user minimized app, service is still running in the background, when the ping notification gets to the device, it shows new notification dialog, but when you want to accept the call and to show fragment, it is not possible because.
1. I don't have current screen on which to show dialog fragment with calling
2. If I create some instance of the current Activity onCreate, and I don't destroy it onDestroy, I can call startActivity on it, but nothing shows up. Call establishes, but I cannot maximize my current activity and show dialog fragment on it.
What can I do in this case? Should I also create some other notification like this one in service and instead of dialog fragment I should be showing another notification?
Related
I have a widget that launches a dialog with two options. One Button to make emergency call, and another to call customer service. Once the dialog is launched from a widget, and I tap on one of the two option, the button doesn't respond. But, if I background the app and bring it to foreground, then that previous selection of the button that I made gets called. I'm using the correct flag when launching the activity from the Widget.
The order of the lifecycle of the Fragment that takes place when things are working normally with the Dialog is below. The similar lifecycle takes place when foreground and backgrounding the app. Not exactly sure why the callback for the buttons on the Dialog doesn't respond when launched from the Widget. Thank you!
OnCreateView()
OnViewCreated()
OnStart()
OnResume()
I was able to fix this problem by simply using navController.navigate(). This allows the NavController to handle the Fragment lifecycle properly and in the correct order.
I want to show an Dialog Whatever the screen the User is in. Suppose if user opens application and in initial screen if I receive a server message I have to show it in a dialog.Meanwhile there is an option of autologin . So it could move to my next activity.If this is the case that dialog should not be closed.It should show on newly opened activity rather than the previous activity.And other thing is that even though the dialog is shown I should be able to control my buttons on the activity.
Here's what i am doing.
if(Activity1.mcontext!=null){
CommonMethods.showDialog(sliderMessageText,
LoginActivity.mcontext,"activity1");
}
if(Activity2.context!=null){
CommonMethods.showSliderMessageText(sliderMessageText,
Activity2.context,"activity2");
}
if(Activity3.mcontext!=null){
CommonMethods.showSliderMessageText(sliderMessageText,Activity3.context,"activity3");
}
Instead I am displaying the dialog in all the activities.
Thanks in advance.
You may want to consider using an Event driven model such as GreenRobot.
http://greenrobot.org/eventbus/
This would allow you to efficiently handle the scenario you describe.
Alternatively, you can use the LocalBroadcastManager to communicate between different parts of your app.
e.g Send a broadcast message when you want to display a dialog and handle that message in all of your Activities
I have an app with multiple Activity classes. In one part, one is a main screen and the next is a login. The user would open the login screen and enter their info and press a button to submit it. The resulting code opens up an AlertDialog to tell them the registration status, along with some other information. If the registration itself was successful, they will return to the previous activity. But this makes any AlertDialog disappear with it.
I want the background to return to the previous activity so they can see the home page start updating, but I want them to see the alert message long enough to read it.
Yes this is possble. By using a service you can display an alertbox which runs in foreground for a long time. I have done thissame kind of thing for a news app.
It will run in foreground for a long time and when you want to switch you can stop the service than it will dismiss the alert box-.
In my case I displayed a custom view with buttons in the foreground.
I am running a service as soon as application starts. That service will keep checking SQLite for data. If it finds a certain data, a dialog box should pop up (user can be on any activity). Don't want to use notification. How do I pop up Dialog box from a service ?
Short question is you cant. However, you can send an intent to your activity for it to be the one showing the dialog box, or you can start an activity that looks like a dialog.
I have the following problem:
I have an Activity where a user can start a web search showing a new activity to show a progress bar until the results are shown. Now the user can either wait for the results or maybe think about the search parameters, hit the back button and triggering a new search. The search is running in an Async Task and therefor still running if the user hits back.
At the moment the thread finishes it calls some methods on the old activity causing the activity to show a dialog.
This causes the system to crash because the dialog tries to show itself with a reference to an activity that is not longer present on the screen.
How can I achieve a dialog that is only shown if the activity is still active?
Call isFinishing() on your activity.