Introducing XDA:DevCon – A Conference For Developers By Developers
XDA Developers Android and Mobile Development Forum
Forgot your password?
 
Post Reply+
Tip us?
 
chocoboyo
Old
#1  
Member - OP
Thanks Meter 1
Posts: 31
Join Date: Aug 2010
Default [Help] Do my stuff after activity loads

Hello,
I'm trying to do something with my app but i dont know how =) maybe you can help me.

My main activity needs to initialize some parts of the app. It takes 2-5 seconds and I'd like to show the user a progress dialog.
the code im using is like
Code:
ProgressDialog tempdialog= ProgressDialog.show(this, "Loading", "Please Wait");
Config.init();
temdialog.cancel();
But i dont know where to put that code. I tried in onCreate(), onStart() and onResume(). But all them show a blackscreen while initializing and dialog is never shown.

Thanks in advance
 
SimonVT
Old
#2  
Senior Member
Thanks Meter 42
Posts: 208
Join Date: Aug 2010
Don't block the UI thread, use a background thread.
HTC Desire AMOLED
ROM: Oxygen 2.0
Radio: 32.44.00.32U_5.09.05.30_2
The Following User Says Thank You to SimonVT For This Useful Post: [ Click to Expand ]
 
chocoboyo
Old
#3  
Member - OP
Thanks Meter 1
Posts: 31
Join Date: Aug 2010
Thanks for the answer. I post my solution for helping others with the same problem

Code:
public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        pd=ProgressDialog.show(this, "Loading", "Please wait");

        Thread t = new Thread() {

	          public void run() {
	        	  try {
					Config.init();
					myHandler.sendEmptyMessage(0);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}

	          }
	      };
	      t.start();
}
public Handler myHandler=new Handler()  {
     public void handleMessage(Message msg) { 
        pd.hide();
     } 
};
 
Post Reply+
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Go to top of page...