Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6727047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:00:06+00:00 2026-05-26T10:00:06+00:00

I’ve got an activity that shows some item from a list. When swiping from

  • 0

I’ve got an activity that shows some item from a list.

When swiping from right to left the same activity is started with the next product and when swiping from left to right I start the same activity with the previous product.

I get the product position from a global array using a member variable position that I decrement when going to previous product and increment when going to next product, and that I pass as an extra in the intent.

The issue is that when pressing the back button, the position value remains the same as that in the activity where I’m coming from. I understand that onResume is called instead of onCreate and that no extra is passed, but position is not static and I expect it to keep its value in the activity instance. Why is this not the case?

Thanks

public class ProductHome extends Activity{  

    private int position;
    private Product product;

    private GestureDetector gestureDetector;
    View.OnTouchListener gestureListener;

    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.product_home);

        position = getIntent().getIntExtra("Position", -1);

        product = GlobalData.map_products.get(product_id);

        // swipe detector
        // left -> right: position++
        // right -> left: position--
        // then starts same activity again

        gestureDetector = new GestureDetector(new SRPGestureDetector());
        gestureListener = new View.OnTouchListener() 
        {
            public boolean onTouch(View v, MotionEvent event) 
            {
                if (gestureDetector.onTouchEvent(event)) 
                {
                    return true;
                }
                else{
                    return false;
                }
            }
        };

        RelativeLayout product_home = (RelativeLayout) findViewById(R.id.product_home);
        product_home.setOnTouchListener(gestureListener);
    }
}   
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T10:00:06+00:00Added an answer on May 26, 2026 at 10:00 am

    This has to do with the mode you launch your activity in. Most likely, there is only one instance of your activity.

    You probably should not launch a new activity when slinging to the right, and probably not use the back button to go back to the previous product, but rather to the list where you probably com from

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.