Look, I have the following code:
My Action:
final Intent intent = new Intent(getApplicationContext(), MyService.class)
.putExtra(UploadService.EXTRA_RESULT_RECEIVER, new ResultReceiver(null) {
@Override
protected void onReceiveResult(int resultCode, Bundle resultData) {
super.onReceiveResult(resultCode, resultData);
String result = resultData.getString(MyService.EXTRA_RESULT_SUCCESS);
...
imageView.setBackgroundDrawable(bitmap);// here my code fails
}
})
MyService:
Bundle b = new Bundle();
b.putString(EXTRA_RESULT_SUCCESS, response.toString());
resultReceiver.send(0, b);
And my application fails on line "imageView.setBackgroundDrawable(bitmap)" with the following exception:
11-13 16:25:38.986: ERROR/AndroidRuntime(3586): FATAL EXCEPTION: IntentService[MyService]
android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
But this doesn't happen when I define receiver like this (with handler):
new ResultReceiver(new Handler()){.../*here goes the same code as in the first example. nothing has been changed*/}
So. It doesn't fail when I pass a default Handler. And I ask Why? In both ways my code is invoked, but when no Handler specified it fails. What influence does Handler have?