按下后退按钮恢复警报对话框状态

时间:2013-08-08 05:48:28

标签: android android-alertdialog resume

我必须在我的Android应用程序中处理Alert Dialog。在我的第一个活动中有一个警报对话框。在特定操作中,会出现警告对话框。当用户单击“警报对话框”的“是”按钮时,用户将移至第二个活动。在我的第二个活动中,我有一个按钮。按下此按钮时,应再次以相同的状态提示“警告对话框”。是否可以恢复按下后退按钮上的警报对话框状态?对话框的代码......

// Alert Dialog for input
@Override
protected Dialog onCreateDialog(int id) {

    AlertDialog dialogDetails = null;

    switch (id) {

    case DIALOG_LOGIN:
        LayoutInflater inflater = LayoutInflater.from(this);
        View dialogview = inflater.inflate(R.layout.dialog, null);
        AlertDialog.Builder dialogbuilder = new AlertDialog.Builder(this);
        dialogbuilder.setView(dialogview);
        dialogDetails = dialogbuilder.create();
        break;

    case LIST_DIALOG :
        LayoutInflater inflater2 = LayoutInflater.from(this);
        View dialogview1 = inflater2.inflate(R.layout.listdialog, null);
        AlertDialog.Builder dialogbuilder2 = new AlertDialog.Builder(this);
        dialogbuilder2.setView(dialogview1);
        dialogDetails = dialogbuilder2.create();

    }

    return dialogDetails;
}

@Override
protected void onPrepareDialog(int id, Dialog dialog) {

    switch (id) {
    case DIALOG_LOGIN:

        final AlertDialog alertDialog = (AlertDialog) dialog;
        Button btnSave = (Button) alertDialog.findViewById(R.id.btnSave);
        Button btnCancel = (Button) alertDialog.findViewById(R.id.btnCancel);
        etList = (EditText) alertDialog.findViewById(R.id.etList);

        btnSave.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) 
            {
                newList = etList.length();
                // TODO Auto-generated method stub
                if ( newList <= 0) 
                {
                    etList.requestFocus();
                    Toast.makeText(getBaseContext(), "Enter Name of List", 1000).show();
                } 

                else 
                {
                    listData = etList.getText().toString().replaceAll(System.getProperty("line.separator"), "");
                    if(listData.length() > 0)
                    {
                        dataPass(listData);
                        createfile(listData);
                    }

                    else
                    {
                        Toast.makeText(getBaseContext(), "Enter Name of List", 1000).show();
                    }

                }
            }
        });

        btnCancel.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                dismissDialog(DIALOG_LOGIN);
                etList.setText("");
            }
        });

        break;


    case LIST_DIALOG:

        AlertDialog alertDialog1 = (AlertDialog) dialog;

        lvDialog = (ListView) alertDialog1.findViewById(R.id.list1);
        TextView tvAdd = (TextView) alertDialog1.findViewById(R.id.txtAdd);

        tvDone = (TextView) alertDialog1.findViewById(R.id.txtDone);


        if(listName.length() <= 7)
        {
            tvAdd.setText("Add Friends to" +" " + listName );
        }

        else
        {
            tvAdd.setText("Add Friends to" +" " + listName.substring(0, 5) + "..");
        }

        tvDone.setOnClickListener(new OnClickListener() {

            @SuppressWarnings("deprecation")
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
            if( colorRow > 0 )
                {
                    AlertDialog builder = new AlertDialog.Builder(NewFriendList.this).create();
                    builder.setTitle("Save to List");
                    builder.setMessage("Do You Want to Save?");
                    builder.setButton("Save", new DialogInterface.OnClickListener() 
                    {

                        public void onClick(DialogInterface dialog, int which) 
                        {               
                            removables = new ArrayList<String>();
                            for(int c= 0; c<checked.size(); c++)
                            {
                                int key = checked.keyAt(c);
                                if(checked.get(key, false))
                                {
                                    removables.add(arr2.get(key));
                                    meMap.put(listName, arr2.get(key));
                                }
                            }


                            try 
                            {
                                writeToFile(removables , listName);
                                dismissDialog(LIST_DIALOG);

                            } 
                            catch (IOException e) 
                            {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }

                        }
                    });

                    builder.setButton2("Cancel", new DialogInterface.OnClickListener() 
                    {
                        public void onClick(DialogInterface dialog, int which) 
                        {

                            chkText.setTextColor(Color.BLACK);
                            colorRow = 0;
                        }

                    });
                    builder.show();
                    }

                    else
                        Toast.makeText(getBaseContext(), "Select Friends", 1000).show();
            }
            });


        lvDialog.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1,
                    int arg2, long arg3) {
                // TODO Auto-generated method stub

                checked = lvDialog.getCheckedItemPositions();
                chkText = (CheckedTextView) arg1.findViewById(R.id.txt);

                if(checked.get(arg2))
                {
                    chkText.setTextColor(Color.CYAN);
                    colorRow ++;
                }
                else
                {

                    chkText.setTextColor(Color.BLACK);
                    //colorRow--;
                    colorRow = 0;

                }


            }
        });


        // Cancel Alert Dialog
        ImageView ivCancel = (ImageView) alertDialog1.findViewById(R.id.imgCancel);
        ivCancel.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                dismissDialog(LIST_DIALOG); 
                arr2.clear();
        }
        });

        // Friend List
        showFriendList();

        break;

    }

logcat的

??-?? ??:??:??.???: INFO/<unknown>(<unknown>): Displayed com.example.addnewlist/.FinalList: +1s140ms
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): [ 08-08 07:14:14.259  5320: 5320 D/AndroidRuntime ]
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): Shutting down VM
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): [ 08-08 07:14:14.259  5320: 5320 W/dalvikvm ]
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): [ 08-08 07:14:14.290  5320: 5320 E/AndroidRuntime ]
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): FATAL EXCEPTION: main
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): java.lang.IllegalStateException: System services not available to Activities before onCreate()
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at android.app.Activity.getSystemService(Activity.java:4463)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at android.view.LayoutInflater.from(LayoutInflater.java:210)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at com.example.addnewlist.NewFriendList.onCreateDialog(NewFriendList.java:182)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at com.example.addnewlist.FinalList$1.onClick(FinalList.java:56)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at android.view.View.performClick(View.java:4204)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at android.view.View$PerformClick.run(View.java:17355)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at android.os.Handler.handleCallback(Handler.java:725)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at android.os.Handler.dispatchMessage(Handler.java:92)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at android.os.Looper.loop(Looper.java:137)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at android.app.ActivityThread.main(ActivityThread.java:5041)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at java.lang.reflect.Method.invokeNative(Native Method)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at java.lang.reflect.Method.invoke(Method.java:511)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at dalvik.system.NativeStart.main(Native Method)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): [ 08-08 07:14:14.319   278:  443 W/ActivityManager ]
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):   Force finishing activity com.example.addnewlist/.FinalList
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): [ 08-08 07:14:14.319   278:  443 W/WindowManager ]
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): Failure taking screenshot for (246x410) to layer 21025
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): [ 08-08 07:14:14.559   278:  295 I/Choreographer ]
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): Skipped 40 frames!  The application may be doing too much work on its main thread.
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): [ 08-08 07:14:14.559    37:  313 E/SurfaceFlinger ]
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): ro.sf.lcd_density must be defined as a build property
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): [ 08-08 07:14:14.887   278:  292 W/ActivityManager ]
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): Activity pause timeout for ActivityRecord{413e8ea0 u0 com.example.addnewlist/.FinalList}
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): [ 08-08 07:14:24.373   278:  292 W/ActivityManager ]
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): Launch timeout has expired, giving up wake lock!
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): [ 08-08 07:14:24.924   278:  292 W/ActivityManager ]
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): Activity idle timeout for ActivityRecord{41024d70 u0 com.example.addnewlist/.NewFriendList}
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): [ 08-08 07:14:31.718   599:  617 D/ExchangeService ]
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): Received deviceId from Email app: null
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): [ 08-08 07:14:31.718   599:  617 D/ExchangeService ]
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): !!! deviceId unknown; stopping self and retrying
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): [ 08-08 07:14:36.759   599:  615 D/ExchangeService ]
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): !!! EAS ExchangeService, onCreate
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): [ 08-08 07:14:36.769   599:  599 D/ExchangeService ]
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): !!! EAS ExchangeService, onStartCommand, startingUp = false, running = false
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): [ 08-08 07:14:36.769   599:  599 D/ExchangeService ]
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): !!! EAS ExchangeService, onStartCommand, startingUp = true, running = false
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): [ 08-08 07:14:36.789   278:  290 W/ActivityManager ]
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): Unable to start service Intent { act=com.android.email.ACCOUNT_INTENT } U=0: not found
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): [ 08-08 07:14:36.789   599:  614 D/ExchangeService ]
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): !!! Email application not found; stopping self
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): [ 08-08 07:14:36.800   278:  442 W/ActivityManager ]
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): Unable to start service Intent { act=com.android.email.ACCOUNT_INTENT } U=0: not found
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): [ 08-08 07:14:36.809   599:  599 E/ActivityThread ]
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40cd3578 that was originally bound here
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40cd3578 that was originally bound here
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at android.app.ContextImpl.bindService(ContextImpl.java:1418)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at android.app.ContextImpl.bindService(ContextImpl.java:1407)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at com.android.emailcommon.service.AccountServiceProxy.getDeviceId(AccountServiceProxy.java:116)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at com.android.exchange.ExchangeService.getDeviceId(ExchangeService.java:1249)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1856)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at android.os.AsyncTask$2.call(AsyncTask.java:287)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at java.util.concurrent.FutureTask.run(FutureTask.java:234)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at java.lang.Thread.run(Thread.java:856)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): [ 08-08 07:14:36.819   599:  599 E/StrictMode ]
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): null
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40cd3578 that was originally bound here
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at android.app.ContextImpl.bindService(ContextImpl.java:1418)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at android.app.ContextImpl.bindService(ContextImpl.java:1407)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at com.android.emailcommon.service.AccountServiceProxy.getDeviceId(AccountServiceProxy.java:116)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at com.android.exchange.ExchangeService.getDeviceId(ExchangeService.java:1249)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1856)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at android.os.AsyncTask$2.call(AsyncTask.java:287)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at java.util.concurrent.FutureTask.run(FutureTask.java:234)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at java.lang.Thread.run(Thread.java:856)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): [ 08-08 07:14:36.819   278:  289 W/ActivityManager ]
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): Unbind failed: could not find connection for android.os.BinderProxy@4128da70
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): [ 08-08 07:14:36.819   599:  599 E/ActivityThread ]
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40cfb5d0 that was originally bound here
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40cfb5d0 that was originally bound here
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at android.app.ContextImpl.bindService(ContextImpl.java:1418)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at android.app.ContextImpl.bindService(ContextImpl.java:1407)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at com.android.emailcommon.service.ServiceProxy.test(ServiceProxy.java:191)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1850)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at android.os.AsyncTask$2.call(AsyncTask.java:287)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at java.util.concurrent.FutureTask.run(FutureTask.java:234)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at java.lang.Thread.run(Thread.java:856)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): [ 08-08 07:14:36.839   599:  599 E/StrictMode ]
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): null
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40cfb5d0 that was originally bound here
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at android.app.ContextImpl.bindService(ContextImpl.java:1418)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at android.app.ContextImpl.bindService(ContextImpl.java:1407)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at com.android.emailcommon.service.ServiceProxy.test(ServiceProxy.java:191)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1850)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at android.os.AsyncTask$2.call(AsyncTask.java:287)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at java.util.concurrent.FutureTask.run(FutureTask.java:234)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>):     at java.lang.Thread.run(Thread.java:856)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): [ 08-08 07:14:36.839   278:  418 W/ActivityManager ]
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): Unbind failed: could not find connection for android.os.BinderProxy@4128d2f0

2 个答案:

答案 0 :(得分:0)

如果您的问题是可能的, 是的,是的。

修改

以下是示例代码,这可能会对您有所帮助。

在您的活动中A1:创建Method dialog并传递参数上下文,在第二个活动中需要该参数以显示Dialog。看到了

public void dialogActivity(final Context c ,int dvalue ){
  if(dvalue==1){
    AlertDialog.Builder builder1 = new AlertDialog.Builder(c);
    builder1.setMessage("Please fill all the fields");
    builder1.setCancelable(true);
    builder1.setPositiveButton("ok", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            Intent i = new Intent(c, A2.class);
        startActivity(i);
            dialog.dismiss();
                }
    });

    AlertDialog alert11 = builder1.create();
    alert11.show();
    }
    else{
  AlertDialog.Builder builder12 = new AlertDialog.Builder(c);
    builder12.setMessage("Please fill all the fields");
    builder12.setCancelable(true);
    builder12.setPositiveButton("ok", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            Intent i = new Intent(c, A2.class);
        startActivity(i);
            dialog.dismiss();
                }
    });

    AlertDialog alert12 = builder12.create();
    alert11.show();

  }

现在拨打您想要的Dialog方法,我在backPressed

上调用它
 @Override
 public void onBackPressed() {
        dialogActivity(A1.this,1);
}

然后在你的第二个活动中你必须创建一个活动A的对象然后你可以使用该功能:

  A1 ma = new A1();

然后在按下Activity时,您可以拨打对话框。

    @Override
public void onBackPressed() {

    ma.dialogActivity(A2.this,1);
}

仅供参考:从自身调用活动A2可能会显示错误。 但是这里是你在不同活动中实现对话框的方式。

答案 1 :(得分:0)

试试这个

@Override
public void onBackPressed() {

    showAlertDialog();

}

showAlertDialog()函数

  private void showAlertDialog() {
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(CheckOutScreenActivity.this);

    // set title
    alertDialogBuilder.setTitle("Confirmation");

    // set dialog message
    alertDialogBuilder.setMessage("Message").setCancelable(false).setPositiveButton("Yes", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {

        }
    }).setNegativeButton("No", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            dialog.cancel();
        }
    });

    // create alert dialog
    AlertDialog alertDialog = alertDialogBuilder.create();

    // show it
    alertDialog.show();
}