1

这在单独的进程中运行。我正在使用远程辅助。我创建了一个方法位图并显示从服务到活动的图像。现在当服务崩溃时,如何显示服务崩溃的消息并禁用活动中的进度对话框?

活动.java

  ServiceSync service;

   private ServiceConnection sync_service_connection = new ServiceConnection() {
    @Override
    public void onServiceConnected(ComponentName name, IBinder iservice) {
        sync_service = IDownloadBoundServiceSync.Stub.asInterface(iservice);
        sync_bound = true;
    }
    @Override
    public void onServiceDisconnected(ComponentName name) {
        sync_bound = false; 
    //this should be displayed in UI by cancelling progress dialog  

        Toast.makeText(getApplicationContext(), "Service crashed", Toast.LENGTH_SHORT)
        .show();

    }
};
     public void buttonclick(View view) {
     bindService(new Intent(context, ServiceSync.class), sync_service_connection, context.BIND_AUTO_CREATE);
    Log.d(getClass().getSimpleName(), "Download with sync");
    prog_diag = ProgressDialog.show(context, "Download", "Downloading..please wait!", true);
    prog_diag.setCancelable(false);

    if (sync_bound) {

        (new Thread() {
            @Override
            public void run() {
                try {
                    final Bitmap file_name=sync_service.getBitmapFromURL(url_box.getText().toString());
                     Log.d(getClass().getSimpleName(), "Received file name from Sync Service");
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            if(file_name!=null)
                            {
                           displaybitmap(file_name);
                            }
                            else
                            {

                                prog_diag.dismiss();
                            }

我正在使用使用aidl的位图方法

4

0 回答 0