|
||
|
![]() |
![]() |
Programación y Desarrollo para Android Subforo exclusivo para temas de programación de software para PDAs y desarrollo de aplicaciones, interfaces, etc bajo Android |
![]() |
|
Herramientas |
#1
|
||||
|
||||
Toast en Intent
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: [PHP]@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; }[/PHP] ya intente poniendo el toast antes y despues del el intent y no aparece nada |
|
#2
|
||||
|
||||
Si quieres actualizar la UI tienes que mostrar el toast en el onPostExecute. Devuelve en el doInBackground en vez de null, un valor x dependiendo de si has ejecutado o no el intent y en el onPostExecute usa ese valor para lanzas el toast diciendo si se ha ejecutado o no el intent. Corregidme si me equivoco.
Un saludo!
__________________
Mis apps en Google Play.
Última edición por joselehhh Día 22/05/15 a las 11:53:34. |
#3
|
||||
|
||||
Si quieres actualizar la UI tienes que mostrar el toast en el onPostExecute. Devuelve en el doInBackground en vez de null, un valor x dependiendo de si has ejecutado o no el intent y en el onPostExecute usa ese valor para lanzas el toast diciendo si se ha ejecutado o no el intent. Corregidme si me equivoco.
Un saludo! ![]() |
Gracias de parte de: | ||
#4
|
||||
|
||||
El toast puedes llamarlo desde donde quieras sí. A mí muchas veces se me olvida llamar al método show() y me quedo un rato mosca hasta que me doy cuenta... lo comento por si acaso ;)
__________________
El mejor Cuatro en Raya de Android (Hilo en HTCMania, Play Store) ¡Un millón de descargas!
|
Gracias de parte de: | ||
#5
|
||||
|
||||
Lo puse aqui y si funciona, justo debajo del doInBackground:
[PHP] @ Override protected void onPostExecute(Void args) { // Lo cate the listview in listview_main.xml listview = (ListView) findViewById(R.id.listview); // Pass the results into ListViewAdapter.java adapter = new ListViewAdapter(MainActivity.this, arraylist); // Set the adapter to the ListView listview.setAdapter(adapter); // Close the progressdialog mProgressDialog.dismiss(); if(jsonobject==null){ Toast.makeText(getApplicationContext(), "No hay conexion a internet!", Toast.LENGTH_SHORT).show(); } }[/PHP] Muchas gracias |
![]() |
![]() |
||||||
|
Herramientas | |