onresume non viene eseguito correttamente quando si ritorna dalle impostazioni
Domanda
Nella mia app, quando non esiste una connessione WiFi, accendo la connessione WiFi con un AlertDialog e chiamo la schermata delle impostazioni WiFi. Quando premo il pulsante Indietro, presumo che vada nel metodo OnResume () della Mainttività. In questo metodo, chiamo un metodo LoadTweets, che ricarica i miei tweet. Funziona quando salgo da un'attività all'altra.
Quando sono tornato nella schermata delle impostazioni WiFi, il debugger va nel metodo OnResume, si supera il metodo LoadTweets, ma non mostra i tweet ricaricati.
Mi manca un passo qui?
Metodo onResume ():
public void onResume(){
super.onResume();
checkWifi();
loadTweets();
}
Metodo 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;
}
Classe 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;
}
}
Nessuna soluzione corretta
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow