0

私は自分のアプリケーションで最初に asynchtask で表示されたスプラッシュ スクリーンの間を行き来したいです。私はスプラッシュ 5 秒で開始し、次に asynchtask を開始します。

public class SplashActivity extends Activity {

    private static String Spsc = SplashActivity.class.getName();
    private static long time = 5;   
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        this.requestWindowFeature(Window.FEATURE_NO_TITLE); 
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);  // Removes notification bar
        setContentView(R.layout.splash);
        IntentLauncher launcher = new IntentLauncher();
        launcher.start();
    }
    private class IntentLauncher extends Thread {
        @Override
        public void run() {
            try {
                Thread.sleep(time*1000);
            } catch (Exception e) {
                Log.e(Spsc, e.getMessage());
            }
            Intent intent = new Intent(SplashActivity.this, MainActivity.class);
            SplashActivity.this.startActivity(intent);
            SplashActivity.this.finish();
        }
    }
}

そして、これは mainActivity からの私のスプラッシュです:

class FetchPosts extends AsyncTask<Void, Void, Void> {
        private ProgressDialog progressDialog;
        @Override
        protected void onPreExecute() {         
            super.onPreExecute();
            progressDialog = ProgressDialog.show(MainActivity.this, "", getString(R.string.loading_message));
        }

        @Override
        protected Void doInBackground(Void... params) {
            articles = Services.getPosts(MainActivity.this);

            return null;
        }

        @Override
        protected void onPostExecute(Void result) {
            super.onPostExecute(result);

            progressDialog.dismiss();

        }
    }
4

2 に答える 2

0

単に

 public class SplashActivity extends Activity {

private static String Spsc = SplashActivity.class.getName();
private static long time = 5;   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    this.requestWindowFeature(Window.FEATURE_NO_TITLE); 
    this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);  // Removes notification bar
    setContentView(R.layout.splash);
    IntentLauncher launcher = new IntentLauncher();
    launcher.start();
}
private class IntentLauncher extends Thread {
    @Override
    public void run() {
        try {
            Thread.sleep(time*1000);
        } catch (Exception e) {
            Log.e(Spsc, e.getMessage());
        }
        //Intent intent = new Intent(SplashActivity.this, MainActivity.class);
        //SplashActivity.this.startActivity(intent);
        //SplashActivity.this.finish();
          new FetchPosts().execute();
    }
   }
public class FetchPosts extends AsyncTask<Void, Void, Void> {
    private ProgressDialog progressDialog;
    @Override
    protected void onPreExecute() {         
        super.onPreExecute();
        progressDialog = ProgressDialog.show(MainActivity.this, "", getString(R.string.loading_message));
    }

    @Override
    protected Void doInBackground(Void... params) {
        articles = Services.getPosts(MainActivity.this);

        return null;
    }

    @Override
    protected void onPostExecute(Void result) {
        super.onPostExecute(result);

        progressDialog.dismiss();

    }
 }
}
于 2013-05-06T16:51:23.720 に答える
0

次のコードを試してください。スプラッシュスクリーン アクティビティが開始されたときに asynctask が開始されます。

public class SplashActivity extends Activity {

private static String Spsc = SplashActivity.class.getName();
private static long time = 5;   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    this.requestWindowFeature(Window.FEATURE_NO_TITLE); 
    this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);  // Removes notification bar
    setContentView(R.layout.splash);
    FetchPosts obj=new FetchPosts();
    obj.execute("dummystring");
 }
}

class FetchPosts extends AsyncTask<String, Void, String> {
    private ProgressDialog progressDialog;
    @Override
    protected void onPreExecute() {         
        super.onPreExecute();
        progressDialog = ProgressDialog.show(MainActivity.this, "", getString(R.string.loading_message));
    }

    @Override
    protected Void doInBackground(String... params) {
        articles = Services.getPosts(MainActivity.this);

        return null;
    }

    @Override
    protected void onPostExecute(Void result) {
        super.onPostExecute(result);

        progressDialog.dismiss();

    }
}
于 2013-05-06T16:54:21.113 に答える