Last active
March 15, 2016 01:15
-
-
Save wakim/0bf03857735324ff011a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mServiceIntent = new Intent(getActivity(), RSSPullService.class); | |
mServiceIntent.setData(Uri.parse(dataUrl)); | |
// Inicia o IntentService | |
startService(mServiceIntent); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<application | |
android:icon="@drawable/icon" | |
android:label="@string/app_name"> | |
<!-- | |
Usar android:exported como "false", | |
faz com que o Service seja visível apenas para esse app. | |
--> | |
<service | |
android:name=".RSSPullService" | |
android:exported="false"/> | |
<application/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class RSSPullService extends IntentService { | |
Handler mHandler = new Handler(); | |
@Override | |
protected void onHandleIntent(Intent workIntent) { | |
// Recupera a url para consumo de dados | |
String url = workIntent.getDataString(); | |
// Realiza o trabalho baseado na dataString | |
Object result = doWorkWithUrl(url); | |
// Notifica possiveis interessados de que o trabalho terminou. | |
EventBus.getDefault().post(new WorkDoneEvent(result)); | |
// Ou usando @Subscribe(threadMode = ThreadMode.MAIN) nos consumidores do evento | |
// Ou caso queira garantir que o evento será disparado na MainThread | |
// em caso de desacoplamento. | |
mHandler.post(new Runnable(){ | |
EventBus.getDefault().post(new WorkDoneEvent(result)); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment