Thank you for the amazing tutorial. I am having an error which is @4.29 seconds. my android studio not recognizing ActivityMainBinding. its showing unresolved rereference: ActivityMainBinding
@@heeDeer had the same issue, import line was missing - in import section of MainActivity.kt (in my case the missing line was "import com.example.apstopwatch.databinding.ActivityMainBinding")
Hello! Awesome and intuitive tutorial! I just had one problem, and that is that every time I close my app (/ turn off my phone) the timer stops running after a minute. Do you have any ideas on how to solve this / what I did wrong? Thank you so much! (by the way, the one thing I know I did differently, is that my timer is in a fragment) :)
Closing the app completely and keeping the timer running. Ive not done something like that personally. Maybe there is a very background thread you could access. But I would guess you would need to ask for some serious permissions to use it
@@casperstockman1799 Yeah looks like that is your best bet. robertohuertas.com/2019/06/29/android_foreground_services/ Have a read of this article i believe this is what you are after :)
I see a lot of similarities between jetpack compose and SwiftUI. And people still use storyboard and UIKit today, well at least I do 😆 To answer your question, no I don't think it will replace all. But the percentage of apps that use Jetpack will continually increase. What are your thoughts on the matter?
@@CodeWithCal Thanks again for replying to my question :) I'm a beginner comparing to other guys but I think that android wants to take place among hybrid development kits , frameworks such as flutter , react native..etc. We can use kotlin already to develop ios apps. In my opinion android with kotlin will join the race using jetpack compose so that most of android developers won't have to learn flutter or something.
I've had some pretty mixed reviews on the speed, personally I always liked the straight to the point tutorials. But sometimes I do admit I go a bit overboard with the speed 😉
where did we get the startService and stopService method from? I don’t have them and the studio swears, I don’t see it in the source code and on the video either
Thanks Cal. Rotating the screen still causes havok. Do we need to update to and pull from the bundle in MainActivity to fix that ? I'm trying to get a perfect timer going but its a lot harder than expected ! Thanks again for your content, I subscribed.
ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-GzwLobVuXXI.html This is a swift and xcode but it will teach the principals of the best way to do this. Save a date to shared preferences then compare the start time to now :)
I want a countdown, for time being I've done 24 hrs timer which is working fine. What I want is when I close my app the timer should continue working. Does it work with services which you've showed in this tutorial. Or there is some other way to achieve this?
So I only learnt this recently but you can save the start time to shared preferences and then compare the current time to the start time. Pretty clever not my idea but I've been meaning to make a video on it :)
I used Service in a different way, it works fine when screen in on, But when I lock the screen the timer gets delayed, and when I turn on the screen again it seems to work fine. If the phone is connected to a power source everything works fine. The issue arises only when the phone is not connected to power and screen goes off. How to avoid this? 😪
I recently discovered you can used shared preferences to save the start timestamp. Then you can compare with current date time. Ive done a video on this for iOS. But the principals should be the same :) ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-GzwLobVuXXI.html
How do I make "Rate Us" and "Send App" in Kotlin language?... I did it in many ways but it doesn't go directly to Google Play Store.... I need help guys!... Right code in fragment... I hope many of you did it if you are app developers by Kotlin
What exactly is the purpose of the strings in the companion object? Did you make them because some of the functions you would be calling required a string in the parameters and you just needed a string to send? Or do the strings "timerUpdated" and "timeExtra" have some special significance?
No the string can be anything. I made those names up. The reason its good practice to put them in a companion object. Is the IDE will pick up if changes are made to the variable. but if you have "timeExtra" somewhere then somewhere else you have "timeExtra1" when they need to be the same. well the IDE wont show you any error messages. Did that make sense? short answer is its good practice
Is the time updating correctly when you hit start? As in is the error only happening on timer stop. Or could it be an error in the regular expression in makeTimeString 06:40?
Triggering something every 15 minutes shouldn't be to hard. Do the math of time if time % (15 min) == 0 then call notif code. Here is an article on a simple notification to user stackoverflow.com/questions/5076165/local-notifications-in-android
Wow such a great video.. I would like to thank u for it. And I wonder.. How to make this example for: Minutes, Seconds and milliseconds?? I've been trying using milliseconds= seconds/1000 and then putting it over the makeString but it didn't work :s
When we start out timer service, in onStartCommand We say timer.scheduleAtFixedRate(TimeTask(time), 0, 1000) the 1000 is milliseconds. So change this to 1 (meaning call the function every millisecond as apposed to every second) then maybe something like this val hours = resultInt % 86400 / 3600 / 1000 val minutes = resultInt % 86400 % 3600 / 60 / 1000 val seconds = resultInt % 86400 % 3600 % 60 / 1000 val milliseconds = resultInt % 86400 % 3600 % 60 Note this is untested, If it does work id love to know :)
Great Tutorial! Thanks a bunch for this!! The problem is I get correct duration that is stored in "time" variable whenever I pressed start and pause and then stop. Great?! But when I pressed start and then stop for the first time without pressing pause, the duration returned is 0.0 Any workaround for this?
Hey, great tutorial! Can you please tell me what do I do if I want to keep the service running even when I remove the application from "recent apps"? thank you!
@@CodeWithCal well, it wasn't so much about usecase but just learning. i figured it out tho, I used foreground service. thanks anyway! this video helped
Personally never had much success implementing any architecture systems. I understand this becomes more important the bigger the scope and the more developers working on the same project. But in my experiences it's been more hassle than it's worth trying to stick to theses structures. That doesn't mean they don't have a place and time and that I don't value clean and concise code.
Nice video! However, I am having an issue at 3:34. Android Studio doesn’t recognise the scheduleAtFixedRate function. Could it be possible it is no longer from the util package that is imported or that it has changed name? I am also having the same trouble with the cancel function at 4:16. Could you help me please?
@@CodeWithCal thanks fir the quick answer! I did import the same 4 packages that you imported, and I also imported more packages trying to troubleshoot this problem
Hello! What worked for me, was saving the paused time in shared preferences then going back and subtracting that time from the current time, if that makes any since (I assume you want the timer to continue when the app is closed).
Your time calculation is very and uneccesarily expensive the, modulo operator is arbitrarily costly depending on the time, at least save the first modulo calculation and then use that as base for the minutes and seconds. i would suggest.
to add millisecond to the stopwatch :) this is the method I've learned from you :) timer.scheduleAtFixedRate(TimeTask(time),0,10) val result = time.roundToInt() val hours = result % 8640000 / 360000 val minutes = result % 8640000 % 360000 / 6000 val seconds = result % 8640000 % 360000 % 6000 / 100 val milliseconds = result % 8640000 % 360000 % 6000 % 100 private fun makingTimeStringFromTimeVariables(hours: Int, minutes: Int, seconds: Int,milliSecs : Int) : String = String.format("%02d:%02d:%02d:%02d",hours,minutes,seconds,milliSecs)