I really don't know how to write the title in the right way, but I will try to explain the issue. I'm working on an app that has like six activities in a sequence, the login is the first activity and once the login is successful I pass the user name to the second activity via bundle and across all the other activities. On the last activity, once the process is successful, it has to go back to the second activity. But, it has to keep the user name. As right now, when the app goes to the second activity, it crashes because it is not getting the user name value, even with the bundle. it is kind of how to make a bundle from two different activities to the same activity.
-
Can you edit with the second activity code? Why it crashes can be for many reasons. I would open a new instance if the second activity and remove the backstack that is not needed at this point. – Sander Rito Feb 27 '19 at 03:40
-
2Use a singleton to store global data instead of trying to pass things around like that. – MarkReedZ Feb 27 '19 at 03:42
-
1Use **SharedPreferences**, to store data values. check the link for reference. [https://stackoverflow.com/a/23024962/3096016] – Sathiamour Feb 27 '19 at 06:05
-
I wil try it, thanks! – jvargas Feb 27 '19 at 12:58
2 Answers
VERY EASY,
Use viewpager with fragments inside activity instead of Activities(Activities also takes much loading time then fragment)
You can use custom non-swipable viewpager which can be found on google easily. - Use Viewpager, - Disable Swiping,
Use click callback on fragments, or EventBus to pass data between activity and fragment.
i would suggest using Eventbus as it a best way for sending and receiving data from-to anywhere.
You can ask me anything more if you are facing any problem.

- 784
- 6
- 19
-
I am new to android, do you have a turotorial for beginners you could share? – jvargas Feb 27 '19 at 21:13
-
Sure, just for viewpager adapter use this https://www.androidhive.info/2015/09/android-material-design-working-with-tabs/ and for event bus, https://android-arsenal.com/details/3/5604 – Sandip Savaliya Feb 28 '19 at 03:20
You have a couple of options to resolve your issue
First Method
Once Login is successful pass in the username using a bundle to the next activity
OnCreate method of MainActivity class retrieve the username
Override the BackPressed method, add a bundle with the username when navigating back to a previous activity to avoid the app from crashing
Second Method
This one is probably less tedious
Use shared preferences to store the username once Login is successful and retrieve the username when needed.
These are two of many ways to solve your problem. Hope this helps

- 735
- 1
- 11
- 17
-
-
I am new to android, do you have a turotorial for beginners you could share? – jvargas Feb 27 '19 at 21:13