Click here to Skip to main content
15,849,907 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I'm developing a location based alarm which is an android appliction.

All the coding part has been done.

But the alarm alert dialog is not displaying when the application is closed.

Please help me, so that i can pop up the alarm even when user is using any other application or he is in home screen.

Below i have mentioned the code of my alarm.

final MediaPlayer mp = MediaPlayer.create(LocAlarmProject.this, R.raw.airtel);               		
mp.start();       		          		
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();



The part which causing me the problem, have made it bold.


Please help.


Regards,
Ramya
Posted
Updated 18-May-12 8:11am
v2
Comments
ledtech3 18-May-12 15:07pm    
The alarm needs to be active at all times waiting for a event to trigger it, then it can start something else or pop up the screen.
Like when waiting for a file or folder change event. If the event listener is not running then it can not respond to a event.
You may want to see if there is a event you could subscribe to to allow it to trigger your app.
Hope this helps some.
ramandroidBE 18-May-12 15:48pm    
this alarm is gonna pop up on location change.It works fine when my application is running.But when the application is closed(ie user may be in home screen or in any other appliction) and on location change i'll get only alert tone(MediaPlayer) but not the alertDialog. And also a error "application has stopped unexpectedly.Please try again".
ledtech3 18-May-12 17:03pm    
Does the app need to "Get Focus" before it trys to pop up the alert.
I can't get the Android IDE to work right on my System so I can't test any Ideas.
ramandroidBE 19-May-12 1:31am    
Actually i'm using onLocationChanged() method in my app. So it works even if this app is closed. But the above given code which is inside this onLocationChange() is not displaying the alert dialog but gives only the sound when the app is closed.
ledtech3 19-May-12 1:51am    
So it is starting the media player but not your Alert box.
What happens if you put the "mp.stop();"
at the end, will that give the dialog a chance to show before it closes the media player. I was wondering if it was the media player that had
"stopped unexpectedly"

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900