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.
Related
I am creating an android service using this code:
var intent = Ti.Android.createServiceIntent({
url : 'service.js'
});
Ti.Android.startService(intent);
As you can see, this service is started only once, it is not called in an interval every X milliseconds. Now when the application is exited (not put to background) and started up again, I would like to retrieve the reference of the service and stop it if the user clicks the stop button. Is there any way of achieving this? Thank you
Stop a Service in app.js by
Identifying the stop button click event and call this to stop service
if(Ti.Android.isServiceRunning(intent){
Titanium.Android.stopService(intent);
}
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 know this has been asked a million times in other forums, but I haven't got a perfect answer yet. This is my requirement:
When the activity goes to bacground, the timer starts and after 10 sec the notification appears. If the user doesn't click on the notification after 10 sec the notification changes.
When the user clicks on the first notification, the last viewed screen appears - i.e the activity comes to the foreground. This is achieved by:
Intent notificationIntent = new Intent(TimedAlert.this, FirstActivity.class);
notificationIntent.setAction(Intent.ACTION_MAIN);
notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
But i want the timer to stop immediately after the activity comes to foreground. I.e in onResume () I give timer.cancel() but this doesn't seem to work. I also tried onNewIntent() but it works only when I am on the first activity when the app goes to background from the second activity. On coming to foreground the onNewIntent() method is not called, even though I have given single top for the second activity.
How can I achieve this behavior?
when the user click on the Notification, the system will call your notificationIntent, in your case the system will start FirstActivity, then in your FirstActivity you can stop the count down.
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.
i am setting an alarm inside of a main activity that is launced whenever a user presses a button..
The alarm is always set for the same time.
Will this cause the alarm to repeat itself more than once in a time period?