onresume no se ejecuta correctamente al regresar desde la configuración
Pregunta
En mi aplicación, cuando no hay conexión WiFi, enciendo la conexión WiFi con un alertdialog y llamo a la pantalla de configuración WiFi. Cuando presiono el botón Atrás, supongo que va en el método onresume () de la MainActivity. En este método, llamo a un método LoadTweets, que recarga mis tweets. Esto funciona cuando salto de una actividad a otra.
Cuando vuelvo a recurrir en la pantalla de configuración de WiFi, el depurador entra en el método OnResume, buce a través del método LoadTweets, pero no muestra los tweets recargados.
¿Me estoy perdiendo un paso aquí?
Método onresume ():
public void onResume(){
super.onResume();
checkWifi();
loadTweets();
}
Método LoadTweets:
private ArrayList<Tweets> loadTweets(){
ArrayList<Tweets> tweets = new ArrayList<Tweets>();
try {
HttpClient hc = new DefaultHttpClient();
HttpGet get = new
HttpGet("http://search.twitter.com/search.json?q=JobXXL_be&rpp=5");
HttpResponse rp = hc.execute(get);
if(rp.getStatusLine().getStatusCode() == HttpStatus.SC_OK)
{
String result = EntityUtils.toString(rp.getEntity());
JSONObject root = new JSONObject(result);
JSONArray sessions = root.getJSONArray("results");
for (int i = 0; i < sessions.length(); i++) {
JSONObject session = sessions.getJSONObject(i);
Tweets tweet = new Tweets();
tweet.setTweet(session.getString("text"));
tweet.setUser(session.getString("from_user"));
tweet.setDate(session.getString("created_at").substring(5,16));
tweets.add(tweet);
}
}
} catch (Exception e) {
Log.e("TwitterFeedActivity", "Error loading JSON", e);
}
return tweets;
}
Clase de TweetListAdapter:
private class TweetListAdaptor extends ArrayAdapter<Tweets> {
private ArrayList<Tweets> tweets;
public TweetListAdaptor(Context context, int textViewResourceId, ArrayList<Tweets> tweets) {
super(context, textViewResourceId, tweets);
this.tweets = loadTweets();
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater vi = (LayoutInflater) getSystemService (Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.tweetitem, null);
}
Tweets o = tweets.get(position);
TextView tt = (TextView) v.findViewById(R.id.TWEET_TEXT);
TextView bt = (TextView) v.findViewById(R.id.TWEET_SCREEN_NAME);
TextView date = (TextView) v.findViewById(R.id.TWEET_CREATED_AT);
tt.setText(o.getTweet());
bt.setText(o.getUser());
date.setText(o.getDate());
return v;
}
public void setTweets(ArrayList<Tweets> tweet){
this.tweets = tweet;
}
}
No hay solución correcta
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow