package ru.abler98.profiwm; import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; import android.content.Intent; import android.os.AsyncTask; import android.os.Bundle; public class SplashScreen extends Activity { String url = "http://test.ru/api/profiwm/index.php"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.splash_screen); new GetTopicTask().execute(url); } private class GetTopicTask extends AsyncTask { @Override protected String doInBackground(String... params) { String result = JSONParser.getJsonFromUrl(params[0]); return result; } @Override protected void onPostExecute(String result) { super.onPostExecute(result); if (result == null) { AlertDialog.Builder builder = new AlertDialog.Builder(SplashScreen.this); builder.setTitle(R.string.error); builder.setMessage(R.string.error_download_data); builder.setCancelable(false); builder.setNegativeButton(R.string.repeat, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); new GetTopicTask().execute(url); } }); AlertDialog dialog = builder.create(); dialog.show(); } else { Intent intent = new Intent(SplashScreen.this, MainActivity.class); intent.putExtra("result", result); startActivity(intent); finish(); } } } }