In Android I am using a service to fetch data from a web service and update the sqlite database with the fetched data.
class IncomingHandler extends Handler {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case MSG_UPDATE_DATABASE:
UpdateListThread thread = new UpdateListThread();
thread.start();
try {
msg.replyTo.send(Message.obtain(null, MSG_UPDATE_DATABASE));
} catch (RemoteException e) {
// client is destroyed
}
break;
default:
super.handleMessage(msg);
}
}
However, If the web service returns an error, I want to throw an Exception and handle the Exception in the UI thread (which binds to this service), so I can print the Exception message on the screen.
Is this possible to do?
TIA,
The recommended method in this case is to use either
ToastorNotificationobjects to notify user. As I understand your program’s logic correctly, you just need to passException‘s message to one of cited object’s constructor and initiate it.