I am in the process of making an application. I currently have a database and a method that uploads pictures (along with data corresponding with the picture/s, stored in the database) using a PHP script on the server. Neither the purpose nor the database’s schema are important. I haven’t really done anything like this before but have looked into it a bit. Basically the user will take a picture with the app. The picture and its data will upload if there is a network connection, but won’t if there is no connection (duh). I want to have the pending images upload once a connection exists.
To do this…My current plans are to use a BroadcastReceiver to detect when the user is connected to a network then use a Service to upload the files. Is this the proper approach? How can I basically go about starting a service when connectivity exists if and only if there are pending uploads?
Your approach sounds reasonable to me in general.
You would register a broadcast receiver with your package, listening for
android.net.conn.CONNECTIVITY_CHANGE.If the activities also trigger your service, you may be able to properly handle every case with an
IntentServicealone, so you won’t have to deal with the many questions around when to stop or start a service with a specific life cycle.Hope this helps; you don’t sound like a beginner so you’ll be able to make ends meet.