I have a view which can be accessed in 3 ways depending on the users’ actions.
For example, I have a shop description page which can be accessed via:
- Searching for the shop
- Clicking on the shop via a Nearby Shops Map Feature
- Clicking on the shop via a list view
The problem I am having is that when the user is on the shop description page, and clicks back, it doesn’t go back to the correct previous page. So if they accessed the shop description via the nearby map feature, clicking back brings them to the listview which is obviously not right.
I tried to solve this problem by using the following code to set a referrer:
SharedPreferences preferences = this.getSharedPreferences("SHARED_PREF",Context.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putString("referrer", "nearby");
editor.commit();
I then checked against this shared preference in the onBackPressed method:
public static void onBackPressed() {
System.out.println("REFERRER NOW EQUALS= "+referrer);
if(referrer == "nearby") {
TabsViewPagerFragmentActivity.mViewPager.setCurrentItem(13);
} else if(referrer == "search-list"){
TabsViewPagerFragmentActivity.mViewPager.setCurrentItem(15);
} else {
TabsViewPagerFragmentActivity.mViewPager.setCurrentItem(10);
}
}
However it still isn’t working right. Is there a better way to solve this? Thanks
You compare strings with :
Instead of == use :