Why don't you create a handler inside of the main activity like this Hander mHandler = new Handler();
Move the anonymous inner Runnable class (which dismisses the dialog) as a named private subclass of the activity called something like "HandlerHelper". Then call mHandler.post(new HandlerHelper()); at the end of the worker thread On Nov 12, 11:24 pm, ΠΑΣΧΑΛΗΣ ΠΛΙΑΧΑΣ <[email protected]> wrote: > I try to load a cursor to an activity and i have this code after some help: > public class ApodEsoListaSec extends Activity { > ProgressDialog mProgressDialog; > ..... > > public void onCreate(Bundle savedInstanceState) { > super.onCreate(savedInstanceState); > setContentView(R.layout.apod_eso2); > > //DEFINING A NEW THREAD WHICH WOULD DO SOME WORK AND THEN DISMISS THE DIALOG > Thread workThread=new Thread(new Runnable(){ > > @Override > public void run() { > > File f = new > File(Environment.getExternalStorageDirectory()+"/DbSample.sqlite"); > CursorFactory factory = null; > > db =SQLiteDatabase.openDatabase(f.toString(), > factory,SQLiteDatabase.NO_LOCALIZED_COLLATORS ); > > ListView list=(ListView)findViewById(R.id.restaurantsApod); > KtiriaId=getIntent().getStringExtra(DiamEso.ID_EXTRA); > EidosApod=getIntent().getStringExtra(DiamEso.ID_Eidos); > String comment; // The generated insult. > model=DbFileApodEso.getAllEntos(KtiriaId,db); > > startManagingCursor(model); > // > adapter=new RestaurantAdapter(model); > list.setAdapter(adapter); > list.setOnItemClickListener(onListClick); > > someTimeConsumingWork(5000); > //ONLY ONE THREAD CAN HANDLE UI, INCLUDES DISSMISSAL OF > //PROGRESS DIALOG. runOnUiThread WILL DO ITS MAGIC HERE! > runOnUiThread(new Runnable(){ > > @Override > public void run() { > mProgressDialog.dismiss(); > Toast.makeText(ApodEsoListaSec.this, "Work done!", > Toast.LENGTH_LONG).show(); > } > > }); > } > > }); > > workThread.start(); > > mProgressDialog=ProgressDialog.show(this, "Work Notify!", "Working > hard, Phew!"); > > private void someTimeConsumingWork(long milisToWork){ > SystemClock.sleep(milisToWork); > > } > > //here are the classes > > class RestaurantAdapter extends CursorAdapter... > > class RestaurantWrapper... > > class DialogWrapper... > > } > > I can see the progressDialog but i eventually get the error > ERROR/AndroidRuntime(6230): Caused by: java.lang.RuntimeException: > Can't create handler inside thread that has not called > Looper.prepare() why is that? And as i try to debug the error i > realized that the error comes up when i call: adapter=new > RestaurantAdapter(model); Any suggestion? -- 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

