本文介绍了Android的完成()活动不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在codeS得到这个错误,当我使用完成(); 的方法完成()是未定义的类型SaveImageTask。我错过了一些声明或任何东西。有人可以请指导我在此。

 公共类SaveImageTask扩展的AsyncTask<字符串,字符串,字符串> {            私人上下文的背景下;
            私人ProgressDialog pDialog;            布尔bCancelled = FALSE;
            公共SaveImageTask(上下文的背景下){
                this.context =背景;
            }            @覆盖
            在preExecute保护无效(){
                // TODO自动生成方法存根                super.on preExecute();                pDialog =新ProgressDialog(背景);
                pDialog.setIndeterminate(假);
                pDialog.setCancelable(真);
                pDialog.setOnCancelListener(cancelListener);
                pDialog.show();            }            @覆盖
            保护字符串doInBackground(字符串参数... args){
                // TODO自动生成方法存根                // 我的东西
                返回null;
            }            @覆盖
            保护无效onPostExecute(字符串参数){
                // TODO自动生成方法存根                pDialog.dismiss();            }            OnCancelListener cancelListener =新OnCancelListener(){
                @覆盖
                公共无效onCancel(DialogInterface为arg0){
                    bCancelled = TRUE;
                    SaveImageTask.this.finish(); //<< ----的方法完成()是未定义的类型SaveImageTask
                }
            };
        }


解决方案

只要使用,

 (活动(上下文))完成()。

编辑:

其实你要投你的上下文活动上下文,

那么你可以使用完成()活动的方法,

喜欢的东西,

 私人活动范围内;公共SaveImageTask(上下文的背景下){
                this.context =(活动)范围内;
            }

现在,只需

  context.finish();

I got this error in my codes when i use finish(); "The method finish() is undefined for the type SaveImageTask" . Am I missing some declarations or anything. Can someone please guide me on this.

    public class SaveImageTask extends AsyncTask<String , String , String> {

            private Context context;
            private ProgressDialog pDialog;

            boolean bCancelled=false;
            public SaveImageTask(Context context) {
                this.context = context;
            }

            @Override
            protected void onPreExecute() {
                // TODO Auto-generated method stub

                super.onPreExecute();

                pDialog = new ProgressDialog(context);
                pDialog.setIndeterminate(false);
                pDialog.setCancelable(true);
                pDialog.setOnCancelListener(cancelListener);
                pDialog.show();

            }

            @Override
            protected String doInBackground(String... args) {
                // TODO Auto-generated method stub

                // MY STUFF
                return null;
            }

            @Override
            protected void onPostExecute(String args) {
                // TODO Auto-generated method stub

                pDialog.dismiss();

            }

            OnCancelListener cancelListener=new OnCancelListener(){
                @Override
                public void onCancel(DialogInterface arg0){
                    bCancelled=true;
                    SaveImageTask.this.finish(); // <<----"The method finish() is undefined for the type SaveImageTask"
                }
            };


        }
解决方案

Just use,

(Activity(context)).finish();

EDIT:

Actually you have to cast your context to Activity Context,

then you can use finish() method of Activity,

Something like,

private Activity context;

public SaveImageTask(Context context) {
                this.context = (Activity)context;
            }

now, just

context.finish();

这篇关于Android的完成()活动不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 06:45