No description, website, or topics provided.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.



WorkerFragment is a mechanism that allows an Activity to start an IntentService and not lose its reply, even if the Activity is recreated (rotation, etc...).

How to use

Simply copy into your project, then on your Activity's onCreate() do this:

this.workerFragment = WorkerFragment.getWorkerFragment(this);

If savedInstanceState == null, you start your IntentService to do some background work:

Intent exampleIntent = new Intent(this, ExampleService.class);
this.workerFragment.putReceiver(exampleIntent); /* this sets the WorkerFragment as receiver */

Then you implement the WorkerFragment.WorkerFragmentReceiver interface in your Activity to handle the result:

public void onReceiveResult(int resultCode, Bundle resultData) {
switch (resultCode)
    case WorkerFragment.RESULTCODE_HELLOWORLD:
        /* do your stuff here */

Now in your IntentService, sending your result is as simple as:

Bundle result = new Bundle();
result.putString(KEY_RESULT, "hello world!");
WorkerFragment.sendResult(intent, WorkerFragment.RESULTCODE_HELLOWORLD, result);