0

I am new to android development so forgive if i asked a silly question. Below i am narrating my requirement and the solution I thought of please read and help me if you have any solution. In my application i have a activity that contain a toolbar on top, different options in the bottom and in the center area a framelayout where i will load fragments that will render different advertisements(Mostly images) based on the options the fragments using viewpager shows multiple images. Check the following image.

enter image description here

Now my problem is let's assume i selected Fashion option with featured sub option then title should be changed to Fashion-Featured and Fragment should show images related to Fashion>featured let's call this fragment fragment1. Now if the user tap on an image then the application will render another fragment lets call it fragment2.

In the fragment2 the selected image will be rendered in large with two buttons More and Stores. Here if the user taps on more button then the thumbnail images of fashion>featured option will be displayed so that user can select another image. If the user taps on store button then the another fragment will load let's call it fragment3.

In fragment3 the stores selling that particular product will be listed.

Now my problem is how can i pass the data between activity to fragment1 then fragment1 to fragment2 then from fragment2 to fragment3 so that the if the user press backbutton still the fragment2 should show the fashion>featured images with the tapped image on large and if the user press another backbutton then fragment1 should show fashion>featured option images. The data passing should be fail safe that is if the app goes in the background then come to foreground then also it should work.

Please help me out. I am planning to implement using sqlite database and reference in shared preference. I think this is not an exceptional requirement other application also handles this kind of requirement so i need a better way to achieve this.

SripadRaj
  • 1,687
  • 2
  • 22
  • 33
AmritM
  • 19
  • 5
  • What have you done so far to achieve this? – Ankita Mar 21 '18 at 07:21
  • Thanks for reply @ankita currently i have not done anything but before implementing sqlite with shared preferences approach. I want to know the best ways so that i can implement . – AmritM Mar 21 '18 at 07:25
  • Yes you should try this with Sqlite & sharedPreference. Once you will implement something then you will get the solution for the same. If in case you stuck somewhere then we are here to help you out. – Ankita Mar 21 '18 at 07:27
  • @Ankita what will be the problem if i pass data in Bundle. – AmritM Mar 21 '18 at 07:28
  • No problem as such. but which kind of data you want to send through bundle? – Ankita Mar 21 '18 at 07:29
  • See My problem here is if Fashion>Featured selected then i will pass data to fragment1.Category= Fashion and FlexOption=Featured. Now the fragment1 will show advertisements for Fashion and featured, and if the user selects an advertisement in fragment1 then i will send ad ids like sequence=a1,a2,a3 and selected=a2. Then fragment 2 will read this data show the records now if the user clicks on the store button of a2 ad then i will pass data adid=a2 to fragment3. Now the fragment3 will do the job. But my problem is with backpress. – AmritM Mar 21 '18 at 07:36
  • You also want to pass the product list from the same bundle? – Ankita Mar 21 '18 at 07:41

1 Answers1

0

If you would like to pass some data to a new fragment see this answer: How to pass a variable from Activity to Fragment, and pass it back?

If your fragment is already created you can add some method to it and call this method with required argument.

Alex Shevelev
  • 681
  • 7
  • 14