Wednesday, August 29, 2012

Re: [android-developers] access methods and objects of mainactivity from a sub class

Use a callback...

Thanks,
Justin Anderson
MagouyaWare Developer
http://sites.google.com/site/magouyaware


On Tue, Aug 28, 2012 at 5:16 AM, DarkDucke <darkducke@gmail.com> wrote:
Hello guys, I have a class that queries a webservice for logging, is an AsyncTask, what I need is to update some controls and call a method that is in mainactivity OnPostExecute when triggered by ...

in mainactivity have:
public class MainActivity extends Activity {
    /** Called when the activity is first created. */


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);


    }

    public void btLogarClick(View view) throws ParserConfigurationException, InterruptedException, ExecutionException, TimeoutException {


        TextView txv = (TextView)findViewById(R.id.lbMsg);
        txv.setText("Logando...");


        wsgeral ws = new wsgeral();
        ws.WSLogin(this, "", "");

    }

    public void MostraAct() {

        Intent i = new Intent(this, tlmenu.class);
        startActivity(i);

    }

}


em minha classe

public class wsgeral {



        private Activity a_act;


        public void WSLogin(Activity ac, String xLogin, String xSenha) throws ParserConfigurationException
        {
        a_act = ac;

        pdiws ws = new pdiws();
        ws.execute(new String[] {"AutenticaUsuario", xLogin, xSenha});
        }


    private class pdiws extends AsyncTask<String, Void, String[]> {


        private ProgressDialog progressDialog;

        @Override
        protected void onPreExecute() {

           progressDialog = new ProgressDialog(a_act);
           progressDialog.setMessage("Aguarde...");
           progressDialog.show();

        }


        @Override
        protected String[] doInBackground(String... params) {

                 //..... call the methods of mainactivity here

                return "";

        }


        @Override
        protected void onPostExecute(String[] result) {


                progressDialog.dismiss();



        }

    }

}


=============================

thanks

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment