Posts

Showing posts with the label טיימר

How to update UI from a different thread

     Google has set it’s tone on some tough guidelines for developing android apps, basically there aren’t any strict rules but one very easy to misunderstand. there is a single Thread which is called the “main” thread, or “UI thread” on some places. this is the thread which is in charge on the views and interaction with the users gestures. based on the guidelines of any mobile platform at the moment, all the work that shouldn’t be done on the main thread should be done on background thread. this can be achieved in many ways, you can use AsyncTask, Or A Handler, Or a simple thread with an implementation of the   run() method within the declaration of the runnable. ok, so if I’m pulling some server data, or performing long calculations, pulling stuff from or to the Sqlite database I’ll probably use an AsyncTask. but let’s say for instance that I want to simply update the UI once every couple of seconds (update a TextView or an ImageView’s content etc..),...

Boil an egg app - step by step (step 1 - planning)

Image
     In this tutorial , I will demonstrate how I built the app, from the design, to the logic and the code itself.    This app was written for educational purposes and is free do download on the market at :  Boil An Egg   - for devices with API 1.6 and above.   So what's the deal with this app?   it's main goal is to provide users with an easy and useful tool to boil an egg, sounds funny and a bit redundant, but for me it's actually a real need, for I'm known to make boiled eggs which are too soft, or on the other hand -too hard. so I thought to myself that there's must be an app on the play store which will enable me to time the eggs so they'll be perfect each time.   After searching the market and installing couple of apps I found that they are too complicated for my needs so I decided to write an app for my own.   1. name for the app: simple is good – “Boil An Egg”      package name: becau...

A simple Countdown Timer in Android

Of course we can implement a simple timer using threads but there's a better way out of the box.      The Android SDK offers us a rather simple way to use timers in our apps, Let's see how it works: CountDownTimer timer = new CountDownTimer(maxmillis, 1000) { @Override public void onTick(long lastknowtimer) { int seconds = (int) (lastknowtimer / 1000) % 60 ; int minutes = (int) ((lastknowtimer / (1000*60)) % 60);   tvTimerLabel.setVisibility(View.VISIBLE); tvTimer.setText(String.valueOf(minuts*seconds));     } @Override public void onFinish() { tvTimer.setText("finished"); } }; The  abstract class -  CountdownTimer's constructor receives two parameters (maxmillis which is the amount of milliseconds to countdown from, and the second parameter is the interval in which the tick happens). It has two methods which must be implemented:   1. onTick()   - the ac...