portal47
22/05/15, 00:36:01
Hola, estoy haciendo una app en la que si no hay Internet mando a abrir otro .class pero quiero que también aparezca un toast avisando que es porque no hay internet.
Aqui es donde mando el Intent:
@Override
protected Void doInBackground(Void... params) {
// Create an array
arraylist = new ArrayList<HashMap<String, String>>();
// Retrieve JSON Objects from the given URL address
jsonobject = JSONfunctions.getJSONfromURL("http://cmx.org.mx/wp-content/uploads/json.txt");
if(jsonobject==null){
Intent intent = new Intent(MainActivity.this, CMX.class);
startActivity(intent);
finish();
}else{
try {
// Locate the array name in JSON
jsonarray = jsonobject.getJSONArray("posts");
for (int i = 0; i < jsonarray.length(); i++) {
HashMap<String, String> map = new HashMap<String, String>();
jsonobject = jsonarray.getJSONObject(i);
// Retrive JSON Objects
map.put("title", jsonobject.getString("title"));
map.put("place", jsonobject.getString("place"));
map.put("date", jsonobject.getString("date"));
map.put("content1", jsonobject.getString("content1"));
map.put("content2", jsonobject.getString("content2"));
map.put("imagen", jsonobject.getString("imagen"));
// Set the JSON Objects into the array
arraylist.add(map);
}
} catch (JSONException e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
}
return null;
}
ya intente poniendo el toast antes y despues del el intent y no aparece nada
Aqui es donde mando el Intent:
@Override
protected Void doInBackground(Void... params) {
// Create an array
arraylist = new ArrayList<HashMap<String, String>>();
// Retrieve JSON Objects from the given URL address
jsonobject = JSONfunctions.getJSONfromURL("http://cmx.org.mx/wp-content/uploads/json.txt");
if(jsonobject==null){
Intent intent = new Intent(MainActivity.this, CMX.class);
startActivity(intent);
finish();
}else{
try {
// Locate the array name in JSON
jsonarray = jsonobject.getJSONArray("posts");
for (int i = 0; i < jsonarray.length(); i++) {
HashMap<String, String> map = new HashMap<String, String>();
jsonobject = jsonarray.getJSONObject(i);
// Retrive JSON Objects
map.put("title", jsonobject.getString("title"));
map.put("place", jsonobject.getString("place"));
map.put("date", jsonobject.getString("date"));
map.put("content1", jsonobject.getString("content1"));
map.put("content2", jsonobject.getString("content2"));
map.put("imagen", jsonobject.getString("imagen"));
// Set the JSON Objects into the array
arraylist.add(map);
}
} catch (JSONException e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
}
return null;
}
ya intente poniendo el toast antes y despues del el intent y no aparece nada