Android service communicating with other class instances
first let me describe the logic.
-
The user enables the Upload Photo button to start the transfer service to upload local photos to the server.
-
When the application remains invisible to the user. still keep track of local photos, if new camera photos, upload them immediately. I am using this ContentResolver permission to implement the function.
-
After terminating the application, the user can take new photos, restart the application, scan the local SD card and upload a new photo.
Here is my question:
When should I put step2
in the Service in case the action was destroyed. you should use another service to implement your business step3
.
you can find the source on Github
see original snippet below:
Intent txIntent = new Intent(this, TransferService.class);
startService(txIntent);
Log.d(DEBUG_TAG, "start TransferService");
// bind transfer service
Intent bIntent = new Intent(this, TransferService.class);
bindService(bIntent, mConnection, Context.BIND_AUTO_CREATE);
Log.d(DEBUG_TAG, "try bind TransferService");
Intent monitorIntent = new Intent(this, FileMonitorService.class);
startService(monitorIntent);
Intent cameraUploadIntent = new Intent(this, CameraUploadService.class);
startService(cameraUploadIntent);
this.getApplicationContext().getContentResolver().registerContentObserver(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, false, cameraUploadObserver);
`
So what should I be putting as the cameraUploadObserver service?
source to share
follow the steps to fulfill the requirement:
-
create a service to fulfill two parts of the requirements
-
UI button to start service
-
inside the service class, register an Observer to detect the camera event, the onChange () event files so you can load the photo into the onChange () method
-
register a transfer service, bind the connection and use that to load all local photos according to the onStartCommand () method.
go to github site to view the whole project.
source to share