Name: android-facebook-tumblr-snap
Owner: CodePath
Description: Tumblr client that supports viewing a stream of photos taken by people
Created: 2015-07-02 07:30:56.0
Updated: 2016-12-13 14:08:27.0
Pushed: 2015-07-03 05:20:16.0
Homepage: null
Size: 532
Language: Java
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
Tumblr client that supports viewing a stream of photos taken by people
The objective of this exercise is to understand and implement intent service. IntentService is a base class for Service that handles async request on demand.
Clients send requests through startService(Intent) calls; the service is started as needed, handles each Intent in turn using a worker thread, and stops itself when it runs out of work.
This app is intended to be the base project on top of which new features can be added. We will implement photo upload functionality in this exercise using IntentService.
To use it, clone the project and import it using the following steps:
Once you have imported base app, go ahead and run it, and you should see the following output :
Create your service by extending IntentService
ic class TumblrUploadService extends IntentService
Override onHandleIntent - This method is invoked on the worker thread with a request to process. Only one Intent is processed at a time.
rride
ected void onHandleIntent(Intent intent)
do stuff on worker thread
This is where you will opne Http Connection to upload the bitmap
Launch the service from your activity/fragment
nt uploadIntent = new Intent(this, TumblrUploadService.class);
ntent.putExtra("key", data);
tService(uploadIntent);
The service takes over from here, catching each intent request, processing it, and shutting itself down when it?s all done
Define the Broadcast Receiver - this needs to be done if activity/fragment needs to know and visually update user that request has been processed
ic class ResponseReceiver extends BroadcastReceiver
Override onReceive of the receiver
rride
ic void onReceive(Context context, Intent intent)
/get data from intent and update UI
Broadcast the Result - result broadcasting is done from onHandleIntent of the service
nt broadcastIntent = new Intent();
dcastIntent.setAction(ResponseReceiver.ACTION_RESP);
dcastIntent.addCategory(Intent.CATEGORY_DEFAULT);
dcastIntent.putExtra("key", "data");
Broadcast(broadcastIntent);
Register the broadcast receiver - Register the receiver in the onCreate() method with the appropriate intent filter to catch the specific result intent being sent from the IntentService
ntFilter filter = new IntentFilter(ResponseReceiver.ACTION_RESP);
er.addCategory(Intent.CATEGORY_DEFAULT);
onseReceiver receiver = new ResponseReceiver();
sterReceiver(receiver, filter);