[英]Displaying progress bar before opening Acitivity in Android?
I have two Activity A & B . 我有两个活动A和B。 On click of button of Activity A , i am opening activity B . 单击活动A的按钮时,我正在打开活动B。 On create method of Activity B , it is take more time to open activity due to method execution . 在活动B的创建方法上,由于方法执行,打开活动需要更多时间。 I want to display progress bar while Activity B will opening , after opening progress bar need to close . 我想在活动B将打开时显示进度条,在打开进度条后需要关闭。
Activity B :- 活动B:-
@Override
protected void onCreate(Bundle savedInstanceState) {
BindStaticValues();
GetCalculationOptions(); //calculation from web server
}
public void BindStaticValues()
{
//standard
BindStandard(); //static spinner (not db)
//Spinner 1
array1 = new ArrayList<ObjectMaterial>();
Adapter1 = new DescriptionAdapter(this,
android.R.layout.simple_spinner_item,
array1 );
Adapter1
.setDropDownViewResource(android.R.layout.simple_spinner_item);
sp1.setAdapter(Adapter1 );
//Spinner 2
array2 = new ArrayList<ObjectMaterial>();
Adapter2 = new DescriptionAdapter(this,
android.R.layout.simple_spinner_item,
array2 );
Adapter2
.setDropDownViewResource(android.R.layout.simple_spinner_item);
sp2.setAdapter(Adapter2 );
}
Please suggest me any usable link or sample code. 请给我建议任何可用的链接或示例代码。
For that purpose, You can use AsyncTask . 为此,您可以使用AsyncTask 。
You can use 2 methods inside AsyncTask: 您可以在AsyncTask中使用2种方法:
onPreExecute()
- To display progress bar onPreExecute()
-显示进度栏 doInBackground()
- To perform long running task (in your case, execute method) doInBackground()
-要执行长时间运行的任务(在您的情况下,请执行execute方法) onPostExecute()
- To perform UI update task or start new activity. onPostExecute()
-执行UI更新任务或开始新活动。 You can take this example: http://android.okhelp.cz/asynctask-example-android-with-progressbar/ 您可以使用以下示例: http : //android.okhelp.cz/asynctask-example-android-with-progressbar/
U can call you're method in the doBackground Job and after this u hide u'r progressbar and start u're activity. 您可以在doBackground作业中调用您的方法,然后隐藏进度条并开始活动。 I think thats all 我认为就这些
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.