Solution:
You can use AsyncTask class which will do the background work in background thread while showing another UI(like progressbar,textview with loading or any other layout what ever you like) in UI thread.
You can do this by using the following code snippet.
Suppose you are downloading any thing from internet .here i am sending request to server and reading the response from the server.
The AsyncTask class which will does the background task.
// ASync Task Begin to perform Billing information
private class performBackgroundTask extends Async Task < Void, Void, Void >
private ProgressDialog Dialog = new ProgressDialog( this);
protected void onPreExecute() {
// here you have place code which you want to show in UI thread like progressbar or dialog or any layout . here i am displaying a progressDialog with test please wait while loading......
Dialog.setMessage(" please wait while loading............");
Dialog.show();
}
protected Void doInBackground(Void... params) {
// write here the code to download or any background task.
DownloadVideo(); // example call method which will download vedio .
return null;
}
protected void onPostExecute(Void unused) {
Dialog.dismiss();
// the background task is completed .You can do the code here for next things
}
}
Call this method with the following line whereever you wants .for example like oncreate() or in anybutton handler as follows:
new performBackgroundTask().execute();
Thats it.by this way we can solve the problem.
thanks,
ReplyDeleteI wonder if we can change the progressdialog to a progressBar? Can you post an example for this?
ProgressBar myProgressBar;
ReplyDeleteint myProgress = 0;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d("SuccessfulScreen","Show progress bar and view button to view the content.");
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
//set control made in XML
setContentView(R.layout.success);
Log.d("Progress bar", "Start count progress bar to 10");
myProgressBar=(ProgressBar)findViewById(R.id.progressbar_Library);
new Thread(myThread).start();
Button btn = (Button) findViewById(R.id.view_btn);
btn.setOnClickListener(this);
}
private Runnable myThread = new Runnable(){
@Override
public void run() {
// TODO Auto-generated method stub
while (myProgress<10){
try{
Log.d("myProgress","myProgress count is " +myProgress);
myHandle.sendMessage(myHandle.obtainMessage());
Thread.sleep(1000);
}
catch(Throwable t){
Log.d("catch message","show message" + t.getMessage());
}
}
//---hides the progress bar---
myHandle.post(new Runnable()
{
public void run() {
//---0 - VISIBLE; 4 - INVISIBLE; 8 - GONE---
//myProgressBar.setVisibility(8);
Log.d("successed message","message will show in textview");
TextView textmsg = (TextView) findViewById(R.id.successmessage);
textmsg.setText("The file is now saved to My Library which is located in the More category");
Log.d("successed message","text nmessage" +textmsg.getText());
Button btnview = (Button) findViewById(R.id.view_btn);
//btnview.setEnabled(true); android:enabled="false"
btnview.setVisibility(0);
}
});
}
Handler myHandle = new Handler(){
@Override
public void handleMessage(Message msg) {
// TODO Auto-generated method stub
myProgress++;
myProgressBar.setProgress(myProgress);
}
};
};
This comment has been removed by the author.
ReplyDeleteThis comment has been removed by a blog administrator.
ReplyDeleteI am getting the error at this line
ReplyDeleteprivate ProgressDialog Dialog = new ProgressDialog( this);
The Error is:
The constructor ProgressDialog(AsyncTaskTest.performBackgroundTask) is undefined
I didn't understand what your problem exactly.
ReplyDeleteProbably,this 2 approaches may be useful for you.
1)add the above declaration line in Oncreate() method.
2)instead of
new ProgressDialog( this);
replace "this " with application context (or) classname.this.
please check for any error that is happening in in BackgroundProcess like nullpointers,any exceptions.
thanks. exactly what i was looking for :)
ReplyDeleteInterestingly, a bit of these male enhancement devices and methods own been
ReplyDeleteproved to be Flaccid and Raise states. This may look to elementary
to really do work but sometimes elaboration is possible through the use of male enhancement.
My weblog; site
I don't know if it's just me or if everyone else experiencing problems with your site.
ReplyDeleteIt appears as if some of the text in your content are running off
the screen. Can somebody else please provide feedback and let me know if this is
happening to them as well? This could be a problem with my internet browser because I've had this happen previously. Many thanks
Here is my web-site :: bonuses slots
I know this if off topic but I'm looking into starting my own weblog and was curious what all is required to get set up? I'm assuming having a blog like
ReplyDeleteyours would cost a pretty penny? I'm not very internet savvy so I'm
not 100% certain. Any suggestions or advice would be greatly appreciated.
Thanks
Feel free to surf to my page: best enhancement reviews
If some one needs to be updated with most up-to-date technologies
ReplyDeleteafter that he must be visit this website and
be up to date every day.
Also visit my page ... Genf20 plus
I love what you guys are up too. This type of clever work and exposure!
ReplyDeleteKeep up the wonderful works guys I've incorporated you guys to my own blogroll.
my blog - super charge labrada
I'm amazed, I have to admit. Seldom do I come across a blog that's equally educative and engaging, and without a doubt, you've hit the nail on the head. The problem is an issue that too few people are speaking intelligently about. Now i'm
ReplyDeletevery happy that I came across this during my
hunt for something relating to this.
My website :: buy Total curve
I am not positive the place you're getting your info, but good topic. I needs to spend a while studying much more or working out more. Thanks for excellent information I used to be in search of this information for my mission.
ReplyDeleteVisit my weblog - venapro direction to use
I get pleasure from, cause I discovered exactly what I used to be looking for.
ReplyDeleteYou've ended my 4 day long hunt! God Bless you man. Have a great day. Bye
my web page: tinnitus control
Excellent beat ! I wish to apprentice while you amend your web
ReplyDeletesite, how could i subscribe for a blog web site? The account helped
me a acceptable deal. I had been a little bit acquainted of this your broadcast provided bright
clear idea
Also visit my homepage ... www.nexopia.com
Nice post. I was checking continuously this blog and
ReplyDeleteI am inspired! Very useful info specially the final part :) I handle such info much.
I used to be looking for this certain info for a long time.
Thank you and best of luck.
my page; proactol online
I do trust all of the ideas you've offered in your post. They are very convincing and can certainly work. Nonetheless, the posts are too brief for newbies. May just you please lengthen them a bit from subsequent time? Thanks for the post.
ReplyDeletemy blog ... capciplex
This is a good tip especially to those new to the blogosphere.
ReplyDeleteBrief but very accurate info… Thanks for sharing this one.
A must read article!
My blog post: %anchor_text%
Hello There. I discovered your blog the use of msn. This is a very well written article.
ReplyDeleteI will be sure to bookmark it and come back to learn extra of your helpful info.
Thank you for the post. I'll definitely comeback.
Feel free to surf to my web site: capsiplextruth.net
You can certainly see your enthusiasm in the
ReplyDeletearticle you write. The arena hopes for more passionate writers like you who are not afraid to mention how they
believe. Always follow your heart.
Also visit my web site ... start playing im netz
Good wгite-up. I definitely apprecіatе this ѕite.
ReplyDeleteKeep ωrіting!
Also visit my web blοg - 500fаstcash.
com (http://500fastcashtipspay.weebly.com/)
Thanks for finally writing about > "show ProgressBar while processing in background in ANDROID" < Liked it!
ReplyDeleteHere is my web-site: book of ra free games online
I have been browsing online more than 3 hours today, yet I never found
ReplyDeleteany interesting article like yours. It is pretty worth enough for me.
In my opinion, if all web owners and bloggers made good content as you did, the net will be much more useful than ever before.
Stop by my web page: achat viagra boutique paris
gucci bags online
ReplyDeleteHeya i'm for the first time here. I came across this board and I find It truly useful & it helped me out a
lot. I hope to give something back and help others like you helped
me.
De quelle manière acheter des bitcoins anonymement sur le réseau tout de
ReplyDeletesuite
My web blog; acheter bitcoin
I'm pretty pleased to find this page. I want to to thank you for your time due to this wonderful read!!
ReplyDeleteI definitely loved every part of it and i also have you saved as a favorite to look at
new information in your web site.
Stop by my webpage; voice cabling toronto (http://www.kimjeongim.com/zbxe/?document_srl=621083)
I was very pleased to discover this site. I wanted to thank you for your
ReplyDeletetime due to this wonderful read!! I definitely enjoyed every bit of it and I have you
book-marked to see new stuff in your web site.
Stop by my web page :: hosting service free
ӏt's an amazing piece of writing for all the web visitors; they will get benefit from it I am
ReplyDeletesure.
Review myy web site; how can i rebuild my rebuild credit after chapter 7
Fruits like pears and prunes are high in fiber and so can naturally rectify bowel dysfunction.
ReplyDeleteHere is my homepage ... senna
Awesome! Its truly remarkable post, I have got much clear
ReplyDeleteidea on the topic of from this article.
Here is my webpage web traffic
Quality articles or reviews is the important to invite
ReplyDeletethe viewers to pay a quick visit the web page, that's
what this website is providing.
Here is my web site: dui lawyer portland or