• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Help How do I use intent in such a way that it only switches on two pages without creating any more?

Hi

I was wondering if it is possible to make an app that can switch only between two activities without creating new every time. For example I have MainActivity and Main2Activity. In MainActivity there is a world clock running after pressing a button, and a second button that switch the screen. In the other activity, there is, let's say, a notepad for example and a button that switch back to MainActivity. So, I want to build this app in the way of just switching between these two activities. What I mean by that? Let's run our imagination. We press the first button and the textview which was previously in 00:00:00 format, immediately indicates the world time. Then I press the second button. It brings me to Main2Activity. I write something in the notepad and press the button. It brings me back to MainActivity. I see the world clock still running. I press the second button of MainActivity. It brings me to Main2Activity. Here I see everything I wrote on the first time. I write something additional in there, and press the button again. It brings me back to the MainActivity. I see the world clock still running. I do this process again, and again and again...

I have tried this logic but it definitely didn't work.. I pressed the button, and it indicates the world clock as I thought. Then I pressed the button. It brought me to Main2Activity... I wrote something in there and pressed the button... The world clock was stopped working, and indicated a 00:00:00 by default. I went to notepad, and all the text I wrote was gone! I pressed the "back" button and seen the world clock running, and the text I wrote as well. Then I realized that intent component just creates new pages, that's all!

Now here's the question. How to prevent this happening? How to make this app just switch between activities, instead of creating new pages all the time?


I have explained this as better as I could... I can't explain this better than that.
 
Back
Top Bottom