Hi guys i have a problem with AsyncTask and strings arrays... I have a splashscreen
SplashScreen.java:
public class SplashScreen extends Activity {
private boolean mIsBackButtonPressed;
private static final int SPLASH_DURATION = 6000; //6 seconds
private Handler myhandler;
int thread;
public String[] lista = new String[200];
public String[] Compagnia = new String[200];
public String[] CodiceVolo = new String[200];
public String[] Citta = new String[200];
public String[] OraPrevista = new String[200];
public String[] OraStimata = new String[200];
public String[] StatoVolo = new String[200];
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);
new MyTask().execute("");
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();
}
public class MyTask extends AsyncTask<String, Void, String> {
ProgressDialog prog;
String info;
@Override
protected void onPreExecute() {
prog = new ProgressDialog(SplashScreen.this);
prog.setMessage("Connessione in corso...");
prog.show();
prog.setCanceledOnTouchOutside(false);
prog.setCancelable(false);
thread = 0;
}
@Override
protected String doInBackground(String... params) {
try {
org.jsoup.nodes.Document doc = Jsoup.connect("http://s.eu").timeout(7*1000).get();
org.jsoup.nodes.Element tabella = doc.getElementsByClass("tabella-voli").first();
Iterator<org.jsoup.nodes.Element> iterator = tabella.select("td").iterator();
while(iterator.hasNext()){
thread++;
Compagnia[thread] = iterator.next().text();
CodiceVolo[thread] = iterator.next().text();
Citta[thread] = iterator.next().text();
OraPrevista[thread] = iterator.next().text();
OraStimata[thread] = iterator.next().text();
StatoVolo[thread] = iterator.next().text();
System.out.println("SPLASH: "+CodiceVolo[thread]);
}
}catch (IOException e) {
e.printStackTrace();
}return info;
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
prog.dismiss();
Bundle bundle = new Bundle();
bundle.putString("edttext", "From Activity");
arrivi fragobj = new arrivi();
fragobj.setArguments(bundle);
Intent intent = new Intent(SplashScreen.this, MainActivity.class);
// intent.putExtra("key",CodiceVolo[2]);
SplashScreen.this.startActivity(intent);
// CheckRow();
}
}// FINE THREAD
I want to print my array in another class. in arrivi.java:
public class arrivi extends Fragment {
ListView list;
List<RowItem> rowItems;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View arrivi = inflater.inflate(R.layout.arrivi, container, false);
String strtext = getArguments().getString("edttext");
System.out.println("CODCICE VOLO: "+strtext);
return arrivi;
}
This doesn't work for me... Crash my app... Thank you