Cannot pop() more than once from the static stack
I need to use a static stack in one of my android application. Here's how
i used it:
In the Constants File:
public static Stack<String> st = new Stack<String>();
And in the Activity File, inside the onBackPressed method following logic
is used:
if (!Constants.st.isEmpty()) {
Log.i("CHECK", "Stack is not empty.");
Log.v("CHECK", "PEEK: " + Constants.st.peek());
Constants.st.pop();
if(Constants.st.isEmpty()){
Log.i("CHECK", "Stack is empty.");
}else{
Log.v("CHECK", "PEEK after POP: " + Constants.st.peek());
}
}else{
Log.i("CHECK", "Stack is empty.");
}
Now when i press back button once it works (i mean pop() function works),
then second time it( pop() function ) doesn't. Here is the Log of the
above logic:
: Stack is not empty.
: PEEK: UI_FirstActivity
: Stack is empty.
: Stack is not empty.
: PEEK: UI_SecondActivity
: PEEK after POP: UI_FirstActivity
: Stack is not empty.
: PEEK: UI_FirstActivity
: PEEK after POP: UI_FirstActivity
PS: Another thing is that whenever all these UI.. functions contains
different dynamically created forms shown on the same activity. Now when
we enter/show any method/form its name i.e., UI.. is been pushed in the
stack.
No comments:
Post a Comment