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

  • Home
  • SEARCH
  • 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 8172495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:47:59+00:00 2026-06-06T21:47:59+00:00

I am working on android applications. In my project I have 3 pages. The

  • 0

I am working on android applications. In my project I have 3 pages.

  • The first page consists of 1 button.
  • The second page is consists of the timer code.
  • The third page consists of again a button.

Now my requirement is when I click on the first page button the third page should open and the timer in second page should pause. Again when I click on the third page button
the second page timer should restart the time where it is stopped and should open the first page.

I am struggling to achieve this task.Guide me through it, Suggest what should have been done to do that.

Page1.java

rowTextView.setOnClickListener(new OnClickListener() {
  public void onClick(View v) {

    Intent myIntent = new Intent(v.getContext(),Page3.class);
    startActivity(myIntent);
    finish();                                       
  }
});

Page2.java

public class TimeractivitybestActivity extends Activity {
    EditText e1;
    MyCount counter;
    Long s1;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        e1 = (EditText) findViewById(R.id.editText1);
        counter = new MyCount(15000, 1000);
        counter.start();
     }

    public void method(View v) {

        switch (v.getId()) {

        case R.id.button1:
            counter.cancel();
            break;
        case R.id.button2:
            counter = new MyCount(s1, 1000);
            counter.start();
        }
    }

    public class MyCount extends CountDownTimer {
        public MyCount(long millisInFuture, long countDownInterval) {
            super(millisInFuture, countDownInterval);
        }
        @Override
        public void onFinish() {
            e1.setText("DONE");
        }
        @Override
        public void onTick(long millisUntilFinished) {
            s1 = millisUntilFinished;
            e1.setText("left:" + millisUntilFinished / 1000);
        }
    }
}


Page3.java

public void gobacktopage1(View v)
    {
        Intent myIntent = new Intent(v.getContext(),Page1.class);
        startActivity(myIntent);
        finish();
    }
  • 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-06-06T21:48:01+00:00Added an answer on June 6, 2026 at 9:48 pm

    You can always store the timeLeft which is s1 and use it again like this, Read the comments too

    1) While calling timer,check if you have any stored time

        Page1.java       
        rowTextView.setOnClickListener(new OnClickListener() { 
          public void onClick(View v) { 
            SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
            long time = sp.getLong("time", 0); // get saved time of times
            Intent myIntent = new Intent(v.getContext(),Page3.class); 
            myIntent.putExtra("time", time); // send it to page2
            startActivity(myIntent); 
            finish();                                        
          } 
        }); 
    

    2) Use the time to start time if it’s not 0.

        Page2.java 
    
        public class TimeractivitybestActivity extends Activity {
            EditText e1;
            MyCount counter;
            Long s1;
    
            @Override
            public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.main);
                long time = this.getIntent().getLongExtra("time", 0); // get
                                                                        // saved
                                                                        // time
                time = (time != 0) ? time : 1500;
                e1 = (EditText) findViewById(R.id.editText1);
                counter = new MyCount(time, 1000); // start with saved time
                counter.start();
            }
    
            public void method(View v) {
    
                switch (v.getId()) {
    
                case R.id.button1:
                    counter.cancel();
                    break;
                case R.id.button2:
                    counter = new MyCount(s1, 1000);
                    counter.start();
                }
            }
    
            public class MyCount extends CountDownTimer {
                public MyCount(long millisInFuture, long countDownInterval) {
                    super(millisInFuture, countDownInterval);
                }
    
                @Override
                public void onFinish() {
                    e1.setText("DONE");
                }
    
                @Override
                public void onTick(long millisUntilFinished) {
                    s1 = millisUntilFinished;
                    e1.setText("left:" + millisUntilFinished / 1000);
                }
            }
    
            public void onPause() {
                SharedPreferences sp = PreferenceManager
                        .getDefaultSharedPreferences(this);
                Editor et = sp.edit();
                et.putLong("time", s1); // save time SharedPreference in onPause
                et.commit();
            }
    
        }
    

    3) no change in page 3, I suppose.

        Page3.java 
    
        public void gobacktopage1(View v) 
            { 
                Intent myIntent = new Intent(v.getContext(),Page1.class); 
                startActivity(myIntent); 
                finish(); 
            } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My team is working on an Android project which consists of several Android applications
I am working on android applications. I created two pages i.e Page1 and Page2.
I am working on android applications. In my project I need to create Listview.
i am working on a task scheduler applications as my college project, i have
I am currently working on an android project. I am trying to have an
I am working on my first android project. i am doing a maos based
I am working on a existing android project for my client. I have made
I have a semester long project that I have been working on in Android
I hope you're all good. I am working on an android application project and
I am working with the sample Home application project on http://developer.android.com/resources/samples/Home/index.html I've added another

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.