In my app I have a service which has a BroadcastReceiver which listens to TIME_TICK.
I already could check if a date is reached. So if for excemple the 04.01.2011 11:00 pm is reached there is a vibration alarm.
But how could I open a dialog so that after I unlocked my screen it is shown?
Launch an intent for an activity when the time is reached.
Declare on the manifest a theme for this activity like:
android:theme="#android:style/Theme.Dialog"
and create a view for the activity just like the inside of a dialog, so you don't need to create an AlertDialog.
Related
I currently started developing for Android and ran into a problem.
I made a basic application in wich i can set a timer between 5 and 60 seconds. After a button press an Intent starts a PendingIntent wich will register an alarm in the Android AlarmManager.
I can simply set an alarm for 30 seconds, close my application, remove it from the running application list and wait. Eventhough my application is totally shut down, after 30 seconds my custom made activity with a simple view pops-up and i can stop my alarm.
The problem: even though i removed my APPLICATION from the running app list after i did set an alarm, after it goes of and i pressed the stop alarm button so the activity is closed i see my ACTIVITY in the running app list..... i can click on it and my basic custom made acticity pops-up again.
In the stop button onClick() i call finish() in the onStop() i call super.onStop()....
How to show my custom alarm activity with my stop alarm button and after stopping or snoozing DO NOT show it in the running app list?
Thanks!
You can use android:excludeFromRecents="true" as an attribute for your activity <activity /> tag in your manifest file.
I did an app that receive push notification, but the notification only show in the notification center.
But I saw that when I received a message from whatsapp, it popup a big dialog even I closed the app.
How does it possible?
Some screenshots:
http://2.bp.blogspot.com/-8WTQisLNIL0/T_O_InFxr6I/AAAAAAAACA4/fdh10K0W79s/s1600/PrtScn20120704114902.jpg
http://www.whatsappen.nl/wp-content/uploads/2012/05/popup21.jpg
https://lh4.ggpht.com/Mopo8Uwh3u7mAOqh7_1LBnquLLVe_TaZfeRfZiBx3QoohOVv9qEm1TUNXUEx5MRKrrs=h900
First create a broadcast receiver class by extending BroadcastReceiver and declare it in manifest with intent filter broadcast action. Create an activity and cal only dialog it its onCreate method.Override the onReceive method of broadcast receiver class and call the activitty there. Declare the activity in manifest with
android:theme="#android:style/Theme.Dialog"
In your notification code braocast the intent with specific braodcast action
I'm building an android application with BroadcastReceiver and I want to show a dialog when onReceive starts.
I want to show the dialog on the phone (show the user a dialog no matter where he is, like the whatsapp dialog when you get a message).
How I can do that?
Thanks!
If you want to show a dialog from inside your onReceive of the BroadcastReceiver, inside your broadcast receiver you may start a transparent activity with an alert dialog and NEVER called setContentView(). The activity will have an transparent view and only the alert dialog will show.
Source: show an alert dialog in broadcast receiver after a system reboot
There are many similar posts which talk about this topic. See below questions for code samples and other reviews on the same:
AlertDialog from within BroadcastReceiver?? Can it be done?
How to raise an alert dialog from BroadcastReceiver class?
How can I display a dialog from an Android broadcast receiver?
How to setup Alertbox from BroadcastReceiver
Hope this will help.
I have a custom Chronometer which extends TextView and works as a stopwatch. The Activity that uses this Chronometer is listening for broadcasts from a Service. In this broadcast the Service tells the Activity (and thus the Chronometer) to stop counting. This works fine when keeping the application on foreground.
However, when the Activity is not active (like the user presses the home button), the Activity doesn't get the broadcast, and the Chronometer keeps counting. So when I open the Activity again, the Chronometer is still counting up, when it shouldn't be.
Who can provide me with a solution for this?
Note: the Service does not have any knowledge of the Activity nor the Chronometer. It just sends a broadcast "Hey, I'm done with whatever I was doing!".
Your service should be called with startForeground(int id, Notification notification);
See why...
By the way, your BroadcastReceiver shouldn't be unregistered within your activity. Add it to the manifest with a intent filter COUNTDOWN_STOP or whatever, to achieve this.
I'm developing a location based alarm which is an Android application.
All the coding part has been done.
But the alarm alert dialog is not displaying when the application is closed.
Please help me, I'm trying to pop up the alarm even when user is using another application or is in the home screen.
The code of my alarm at the moment is shown below:
final MediaPlayer mp = MediaPlayer.create(LocAlarmProject.this, R.raw.airtel);
mp.start();
// LocAlarmProject.this below is what's causing the problem:
final AlertDialog.Builder builder=new AlertDialog.Builder(LocAlarmProject.this);
builder.setTitle(disp_title);
builder.setMessage(disp_desc);
builder.setIcon(R.drawable.alarm);
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
mp.stop();
}
});
builder.show();
I am pretty sure you are looking for Service.
Copied and Paste:
A Service is an application component representing either an
application's desire to perform a longer-running operation while not
interacting with the user or to supply functionality for other
applications to use. Each service class must have a corresponding
declaration in its package's AndroidManifest.xml. Services
can be started with Context.startService() and Context.bindService().
Use Notification service to keep track of the status.....visit......http://developer.android.com/guide/topics/ui/notifiers/notifications.html
The proper way to do this requires a few steps. Sorry, it's not trivial if you haven't done it before:
First, you're going to use Android's built-in AlarmManager to schedule the time you want your app to be activated. You schedule a new alarm with the time to wake up and a PendingIntent.
Second, create your PendingIntent that's used to activate your app for the time to show the alarm.
Third, you can handle this Intent several ways, the most common is to create a class that extends BroadcastReceiver to receive the Intent. This class is notified when it's time to show the alarm. The Intent that you created and put inside your PendingIntent is passed to its onReceive() method. You pass this information to your app to display the alert dialog. --- You can alternatively just register your main app to receive the Intent instead, then override the onNewIntent(Intent) method in your Activity.
Four, register your BroadcastReceiver in your AndroidManifest.xml file. This is also the place to register this receiver to listen for the Intent you created. You do this using the <intent-filter> tag.
Five, (optional) if you want your alarm to display even if the phone is asleep, and you want to make sure it doesn't go back to sleep before the user acknowledges the alarm, you'll need to obtain a WAKE_LOCK to do so.
The reason this is preferable to using a Service is it doesn't consume resources just to wait for the alarm, and also it still works if Android decides to kill your app free up memory. Good luck and happy coding!