You cannot affect the UI from doInBackground(). As the stack trace illustrates, this includes showing Toasts. Please move your Toast to onPostExecute().
On Fri, Aug 12, 2011 at 2:51 PM, Mark Ayers <[email protected]> wrote: > I'm working on a drawing app, and the code for my file saving routine goes > like this: > case SAVE_MENU_ID: > Config config = Config.ARGB_8888; > Bitmap mBitmap = Bitmap.createBitmap(mDrawingPanel.getWidth(), > mDrawingPanel.getHeight(), config); > Canvas canvas = new Canvas(mBitmap); > mDrawingPanel.draw(canvas); > Handler saveHandler = new Handler(){ > @Override > public void handleMessage(Message msg) { > final AlertDialog alertDialog = new AlertDialog.Builder(_panel).create(); > alertDialog.setTitle("Saved 1"); > alertDialog.setMessage("Your drawing had been saved :)"); > alertDialog.setButton("OK", new DialogInterface.OnClickListener() { > public void onClick(DialogInterface dialog, int which) { > return; > } > }); > alertDialog.show(); > } > } ; > new ExportBitmapToFile(_panel, saveHandler, mBitmap).execute(null); > return true; > } > > > The ExportBitmapToFile class is as follows: > private class ExportBitmapToFile extends AsyncTask<Intent,Void,Boolean> { > private Context mContext; > private Handler mHandler; > private Bitmap nBitmap; > public ExportBitmapToFile(Context context,Handler handler,Bitmap bitmap) { > mContext = context; > nBitmap = bitmap; > mHandler = handler; > } > @Override > protected Boolean doInBackground(Intent... arg0) { > try { > if (!APP_FILE_PATH.exists()) { > APP_FILE_PATH.mkdirs(); > } > final FileOutputStream out = new FileOutputStream(new File(APP_FILE_PATH + > "/myAwesomeDrawing.png")); > nBitmap.compress(Bitmap.CompressFormat.PNG, 100, out); > out.flush(); > out.close(); > return true; > }catch (Exception e) { > e.printStackTrace(); > } > Toast.makeText(_panel, "Success!", 5); > return false; > } > > @Override > protected void onPostExecute(Boolean bool) { > super.onPostExecute(bool); > if ( bool ){ > mHandler.sendEmptyMessage(1); > } > } > } > The logcat is attached. > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected] > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en -- Mark Murphy (a Commons Guy) http://commonsware.com | http://github.com/commonsguy http://commonsware.com/blog | http://twitter.com/commonsguy Android Training...At Your Office: http://commonsware.com/training -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

