web services - Android wait for network available -


i writing android service executed every 15 minutes.

it requires internet connection because sends request server , if response of server "ok" service executes code.

all works fine if phone not in standby (the screen on), if phone in standby mode connection unavailable , service not work correctly. want service wait available connection , send request server.

for example phone in standby mode , 15 minutes afterwards, service starts , tries send request server connection unavailable. in case want service wait connection become available , send request server.

can suggest should do?

ok never use alarm manager , broadcast receiver please con post example? alarm manager , broadcast receiver work if phone in standby? write write error must execute service every 2 hours not 15 minutes.

when phone goes in standby, cpu stop work, causing processes stop execution. can avoid using powermanager , lock cpu assure stay on when phone goes in standby:

m_wakelock = m_powermanager.newwakelock(                 powermanager.partial_wake_lock, "my tag");  m_wakelock.acquire(); ... cpu assured on during time ... m_wakelock.release(); 

but since need have service wake every 15 min, when in standby, cause hard use of battery. can avoid using alarmmanager, schedule event every 15 minutes, , launch appropriate broadcastreceiver. in broadcastreceiver send service message through intent (launching service parameter in intent), acquire cpu, work, , release cpu.

-------------------------- update -------------------------

first of all, declare broadcastreceiver in manifest:

<receiver         android:name="startupreceiver"         <intent-filter>              <action android:name="my.package.myevent" />              <category android:name="android.intent.category.home" />          </intent-filter> </receiver> 

your broadcastreceiver look similar this:

public class startupreceiver extends broadcastreceiver {      @override     public void onreceive(context context, intent intent) {         intent serviceintent = new intent();         serviceintent.setaction("my.package.myservice");         context.startservice(serviceintent);      }  } 

in way, every time intent action "my.package.myevent" launched using, example, sendbroadcast(intent) method (check here), broadcast receiver (namely, class extends broadcastreceiver class check here) execute it's onreceive() method. in code, create intent appropriate action ("my.package.myservice"), , launch myservice.

alarmmanager class provide way schedule intent launched in future, sendbroadcast() method (check here). cpu stay on during execution of onreceive() method associated alarmmanager. need lock cpu, launch service sure tu executed. in mean time onreceive() method stop, service assured in execution. thing need find workaround on how let service communicate alarmmanager, release cpu lock after service executed, stated in main page of alarmmanager. is, need syncronize service broadcast receiver, using external object save information needed (in case, if cpu locked @ end of service release cpu).


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -