Back to project page SwitchTabs.
The source code is released under:
Apache License
If you think the Android project SwitchTabs listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.normal.testdemo.activitys; /*from www . ja v a 2 s .c o m*/ import android.app.Activity; import android.content.Intent; import android.os.AsyncTask; import android.os.Bundle; import android.util.Log; import android.view.Menu; import com.google.gson.Gson; import com.normal.testdemo.R; import com.normal.testdemo.beans.Hotels; import java.io.InputStreamReader; import java.net.URL; import java.util.Timer; import java.util.TimerTask; /** * Created by ex_chenjinghao on 2014/4/8. * ???????? */ public class SplashActivity extends Activity { public static final String JSON_URL = "https://s3-ap-northeast-1.amazonaws.com/testhotel/hotels.json"; // json????????? public static boolean ready = false; // ??????????Activity??????????? public static Hotels hotels; // ????? public final int SPLASH_DISPLAY_LENGHT = 5000; // ????????? public boolean timeout = false; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_splash); // ???????????????json???? new GetJson().execute(JSON_URL); // ?????? schedule(SPLASH_DISPLAY_LENGHT); } // ?????delay????????? public void schedule(long delay) { // ??????????????????MainActivity???????????????? if (ready && timeout) { Intent intent = new Intent(this, MainActivity.class); intent.putParcelableArrayListExtra("hotels", hotels.getHotels()); startActivity(intent); this.finish(); } else { Timer timer = new Timer(); timer.schedule(new TimerTask() { @Override public void run() { timeout = true; schedule(500); } }, delay); } } @Override public boolean onMenuOpened(int featureId, Menu menu) { menu.add("aedf"); return super.onMenuOpened(featureId, menu); } // ?????????json???? public static class GetJson extends AsyncTask<String, Integer, Hotels> { // ??????????????? @Override protected Hotels doInBackground(String... params) { try { InputStreamReader isr = new InputStreamReader(new URL(params[0]).openStream()); Gson gson = new Gson(); return gson.fromJson(isr, Hotels.class); } catch (Exception e) { e.printStackTrace(); } return null; } // ?????????????????????? @Override protected void onPostExecute(Hotels result) { if (result != null) { hotels = result; ready = true; Log.i("result", ready + ""); } } } }