Reputation: 7841
I read the android developer guide. I got idea about android applcations a lot. But now I really want to develop one application. I have some basic questions in my mind. I would be glad to get their answers from experts.
In my application I need to check for the notification when the SIM card is removed from the phone and when put back. To check this which one will be the good idea? Is it a timer I should implement in my application or should I create a service which can respond to SIM card removal.
If I implement a timer to do a certain job at regular time interval, will the timer still can run if all the activities are in the background?
Upvotes: 0
Views: 163
Reputation: 80340
On all phones that I've seen in order to remove SIM the phone must be shut down, because battery usually blocks the SIM slot. So basically your app can not be notified about SIM removal because phone is off. What you can do is start your Service after phone restarts, via BroadcastReceiver listening for BOOT_COMPLETED: see this tutorial. Service then checks if SIM is available via TelephonyManager.getSimState()
.
Not necessarily. Android OS decides when to kill off and remove from memory the inactive apps. There is no guarantee that your inactive (e.g. in the background) app will not be removed. To guarantee scheduled execution look at AlarmManager
.
Upvotes: 1
Reputation: 13501
for first case you probably need a BroadCast Reciever
(Provided broadcast are sent when sim Card is removed.
and for 2nd case Alarm Manager
is better choice than timer.
Upvotes: 0