0

assume that I have main class A that extends Activity and second, inner class B that extends AsyncTask. What I want to do is to edit instance variable of class A using asyncTask. However, still can't figure out why it does not works. As method get() within AsyncTask is blocking and it takes some time to compute all the things within doInBackground() method, I would like to avoid this solution. However, solution when you assign value to variable inside onPostExecute() method, is not working either. I guess that it should, as this method runs on UI thread, but it does not.

Code:

class A extends Activity{
    private String uri;
    private Bitmap bitmap;


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

        new B().execute(someImage);

        Log.d("Saved Uri", uri);
    }

    private class B extends AsyncTask<Bitmap, Void, String>{
        File outFile;

        @Override
        protected void onPreExecute(){ 
           //Show dialog 
        }

        @Override
        protected String doInBackground(Bitmap... images){
            //Process image and saves it
            //...
            return outFile.getAbsolutePath();
        }

        @Override
        protected void onPostExecute(String s){
            uri = s;
        }
    }
}

Log shows that uri is null ....

Any suggestions are very welcome. Thanks

jpact
  • 1,042
  • 10
  • 23

0 Answers0