GithubHelp home page GithubHelp logo

anthrax3 / android-facebook-tumblr-snap Goto Github PK

View Code? Open in Web Editor NEW

This project forked from codepath/android-facebook-tumblr-snap

0.0 1.0 0.0 532 KB

Tumblr client that supports viewing a stream of photos taken by people

Java 100.00%

android-facebook-tumblr-snap's Introduction

android-facebook-tumblr-snap

Tumblr client that supports viewing a stream of photos taken by people

Overview

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.

Usage

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:

Imgur

Once you have imported base app, go ahead and run it, and you should see the following output :

Imgur

Now, let's understand the steps involved in creating and executing IntentService :

Create your service by extending IntentService

public 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.

@Override
protected 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

Intent uploadIntent = new Intent(this, TumblrUploadService.class);
msgIntent.putExtra("key", data);
startService(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

public class ResponseReceiver extends BroadcastReceiver

Override onReceive of the receiver

@Override
public 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

Intent broadcastIntent = new Intent();
broadcastIntent.setAction(ResponseReceiver.ACTION_RESP);
broadcastIntent.addCategory(Intent.CATEGORY_DEFAULT);
broadcastIntent.putExtra("key", "data");
sendBroadcast(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

IntentFilter filter = new IntentFilter(ResponseReceiver.ACTION_RESP);
filter.addCategory(Intent.CATEGORY_DEFAULT);
ResponseReceiver receiver = new ResponseReceiver();
registerReceiver(receiver, filter);

android-facebook-tumblr-snap's People

Contributors

vibhorb avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.