Skip to content
This repository has been archived by the owner on Nov 8, 2018. It is now read-only.

Fixes #154:Timer doesn't stops in rapidfire #168

Closed
wants to merge 1 commit into from

Conversation

HimanshuS01
Copy link

Fixes #154

Changes
Fix - When app goes in background, the timer should be cancelled in onPause() and when user comes back in onResume(), the new timer should be creating starting from same point (Keeping a variable millisLeft for it)

@chhavip @yatna @MeepyMay Please review my PR.Thanks. :)

Copy link

@chhavip chhavip left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good approach, requires some refinement.

@Override
protected void onPause() {
counter.cancel();
counter= null;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apply proper spacing between the instance and assignment operator. Here and at other places too.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok @chhavip Thank you.I will take care of this from the next time. :)

@Override
protected void onResume() {
if(counter==null){
counter= new RapidFireTimeCounter(millisLeft,1000);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creating a new timer every time is not the best way to go. Utilize .start and .cancel in onPause and onResume and work with a single timer. Also I dont believe there is a need to set the timer to null while cancelling it.

Copy link
Author

@HimanshuS01 HimanshuS01 Jan 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chhavip CountDownTimer once cancelled can't be started again from the same point using the same object. We have to follow this approach only (Cancelling and then creating new Timer which will be given initial time as the time that was remaining i.e millisLeft) :)
As in the mentioned link:
http://stackoverflow.com/questions/15443219/how-to-pause-and-resume-a-timertask-timer?rq=1

Copy link
Author

@HimanshuS01 HimanshuS01 Jan 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also @chhavip I have provided the null check in onResume() because when game starts for first time , both onCreate() and onResume() are called before onStart() of activity => If I don't provide null check, it will create 2 timers - one in onCreate() and other in onResume()
also
in onPause() I have to set timer as null because in onResume() I am providing null check, if I won't set null it won't execute the code in onResume(). :) Thanks

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not have a problem with the null check. The timer does not need to set to null and reinitialised is all I am saying. You can cancel it in onPause and then in onResume set the time from sharedPreffs and start it again.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please search for alternate solutions.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@HimanshuS01 As mentioned,could you come up with another solution?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry for replying late. I was stuck in my exams . Will update you soon with another solution :-)

Copy link
Member

@yatna yatna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@HimanshuS01 Since, other PRs sent are being merged you may get some conflicts, please remember to resolve them. 👍

@HimanshuS01
Copy link
Author

@yatna Thank You for reviewing it. I will resolve the following conflicts.

@geekanamika
Copy link
Member

PR belongs to code before infrastructure changes, closing this PR. Issue will be available to claim, this bug exists in gsoc18-code too.

@geekanamika geekanamika closed this Aug 4, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

Successfully merging this pull request may close these issues.

5 participants