大家好我有2个asynctask和1个splashscreen。我想在splashscreen中执行2 asynctask ... 当2个线程asynctask完成时显示我的应用程序...
public class arrivi extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View arrivi = inflater.inflate(R.layout.arrivi, container, false);
new MyTask().execute("");
public class partenze extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View partenze = inflater.inflate(R.layout.partenze, container, false);
new MyTask().execute("");
return partenze;
}
public class SplashScreen extends Activity {
private boolean mIsBackButtonPressed;
private static final int SPLASH_DURATION = 6000; //6 seconds
private Handler myhandler;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.splashscreen);
//CONTROLLO CONNESSIONE
if (!isOnline()){
try {
AlertDialog alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setTitle("Info");
alertDialog.setMessage("Connessione Internet non disponibile.");
alertDialog.setButton("Esci", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
finish();
}
});
alertDialog.show();
}
catch(Exception e) { }
}
// FINE CONTROLLO CONNESSIONE
myhandler = new Handler();
// run a thread to start the home screen
myhandler.postDelayed(new Runnable()
{
@Override
public void run()
{
finish();
if (!mIsBackButtonPressed)
{
// start the home activity
Intent intent = new Intent(SplashScreen.this, MainActivity.class);
SplashScreen.this.startActivity(intent);
}
}
}, SPLASH_DURATION);
}
//handle back button press
@Override
public void onBackPressed()
{
mIsBackButtonPressed = true;
super.onBackPressed();
}
你可以帮帮我吗?
什么是最简单的方法?
我希望在asynctask完成时显示我的MainActivity ...谢谢!
答案 0 :(得分:0)
继续检查while循环中的那些布尔值。
do {
// Do nothing. Just wait untill both booleans are set.
} while(bool1 && bool2);
// Execute your code which you want to execute after finishing both async tasks
答案 1 :(得分:0)
AsyncTask在完成后提供执行一些代码。 http://developer.android.com/reference/android/os/AsyncTask.html#onPostExecute(Result)
您可以将有关已完成任务的信息发送到方法(例如controllerOfTaskExecution),这将启动您的MainActivity。