i have a set of words in an array and i am displaying them one by one like a slideshow using Handlers. the problem is when i switch mode (land to portrait or vice verse) it starts again from the first word.
i know i have to save the variables in onSaveInstanceState() but the problem is the value of the variable 'i' which i want to save is in a different method (updateUI()).
this is my activity:
public class WatSlideShow extends Activity {
RefreshHandler refreshHandler = new RefreshHandler();
TextView watwords;
int i = 0;
String wat1[] = { "SICK", "FUTURE", "PROBLEM", "DECEIVE", "SUFFER",
"FAITH", "PROTECT", "SUICIDE", "STEP", "WNJOY", "FAIL" };
class RefreshHandler extends Handler {
@Override
public void handleMessage(Message msg) {
// TODO Auto-generated method stub
WatSlideShow.this.updateUI();
}
public void sleep(long delayMillis) {
this.removeMessages(0);
sendMessageDelayed(obtainMessage(0), delayMillis);
}
};
public void updateUI() {
if (i < wat1.length) {
watwords.setText(wat1[i]);
refreshHandler.sleep(3000);
i++;
}
}
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.watslideshow);
updateUI();
}
how should i save the value of 'i' (which is the word being displayed) in onSaveInstanceState().
protected void onSaveInstanceState(Bundle outState) {
// TODO Auto-generated method stub
super.onSaveInstanceState(outState);
int currentI = ? // how to get value of 'i' here
outstate.putInt("Myint", currentI)
}
and then i can use this in oncreate():
int myInt = savedInstanceState.getInt("MyInt");
sorry but my java concepts not strong yet. still learning.