I have an activity in which I call Service on background, I am quite new to AIDL

my codes are as follows:

on Activity

//declaration
private Intent mIntentInvenueService;
private IInvenueService mIInvenueService;

protected void onCreate(Bundle savedInstanceState) {   
    super.onCreate(savedInstanceState);
mIntentInvenueService = new Intent(this, InvenueService.class);
    startService(mIntentInvenueService);
}
private final ServiceConnection mServiceConnection = new ServiceConnection() { 
    @Override
    public void onServiceConnected(ComponentName name, IBinder service) { 
        mIInvenueService = IInvenueService.Stub.asInterface(service);
        try {
            mIInvenueService.registerCallback(mCallback);
        } catch (RemoteException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void onServiceDisconnected(ComponentName name) { 
        mIInvenueService = null;
        try {
            mIInvenueService.unregisterCallback(mCallback);
        } catch (RemoteException e) {
            e.printStackTrace();
        }
    }
};

private final IInvenueServiceCallback.Stub mCallback = new IInvenueServiceCallback.Stub() {
    @Override
    public void onReceiveResponse() throws RemoteException {
        runOnUiThread(new Runnable() {
            public void run() {
                if (flagChanged){

                }
                else
                {
                    cAdapter.notifyDataSetChanged();
                }

            }
        });
    }
};
    public void onResume() {
    super.onResume();
    bindService(mIntentInvenueService, mServiceConnection, BIND_AUTO_CREATE);
}

@Override
public void onDestroy() {  
    super.onDestroy();
    unbindService(mServiceConnection);
    unregisterReceiver(mBroadcastReceiver);
}

ON MY SERVICE:

private final RemoteCallbackList<IInvenueServiceCallback> mCallbacks = new RemoteCallbackList<IInvenueServiceCallback>();
private boolean isUpdated = false;
@Override
public IBinder onBind(Intent intent) {
    return mBinder;
}

private final IInvenueService.Stub mBinder = new IInvenueService.Stub() {
    @Override
    public void startProcess() throws RemoteException {
        Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            public void run() { 
               Toast.makeText(......).show()// Toast Here
            }
        }, 60000, 60000);
    }



    @Override
    public void unregisterCallback(IInvenueServiceCallback callback)
            throws RemoteException {
        mCallbacks.unregister(callback);
    }

    @Override
    public void registerCallback(IInvenueServiceCallback callback)
            throws RemoteException {
        mCallbacks.register(callback);

    }

};

My AIDL:

interface IInvenueService {
void startProcess();
void registerCallback(IInvenueServiceCallback callback);
void unregisterCallback(IInvenueServiceCallback callback);
 }

My Question is why is that the Toast not showing? Am I missing something that start process isnt working?

Any Help?

有帮助吗?

解决方案

You should show Toasts from the UIThread, using a TimerTask will cause it to run on a seperate thread.

Try posting a runnable with the Toast to a Handler.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top