类活动和splash.class。在第一个(执行主程序)中,有asynctask(它将被调用几次)检索数据。第二个活动是一个启动屏幕,一直运行直到下载数据。
public class splash extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash_screen);
startHeavyProcessing();
}
private void startHeavyProcessing(){
new LongOperation().execute("");
}
private class LongOperation extends AsyncTask<String, String, String> {
Intent i = new Intent(splash.this, MainActivity.class);
@Override
protected String doInBackground(String... params) {
startActivity(i);
return "";
}
protected void onPostExecute(String result) {
}
protected void onPreExecute() {
}
protected void onProgressUpdate() {}
}
}
当MainActivity完成检索其doInBackground中的数据时,我想完成spalash活动。完成后,我只会运行MainActivity。
答案 0 :(得分:0)
试试这个!
private class LongOperation extends AsyncTask<String, String, String> {
@Override
protected String doInBackground(String... params) {
return "";
}
protected void onPostExecute(String result) {
if(result != null){
}
Intent i = new Intent(splash.this, MainActivity.class);
startActivity(i);
}else {
Log.e("DOWNLOAD ERRO");
}
protected void onPreExecute() {
}
protected void onProgressUpdate() {}
}