Posts

Showing posts from April, 2017

How to remove a particular activity from android stack?

             Most common problem face, when developing the application which has the circular flow or you can say loop flow. For E.g. Suppose if you move from A ➜ B ➜ C ➜ D ➜ E then from E ➜ C in C you click on some button and move to C ➜ D.             Now when you move from E ➜ C ➜ D it will create another copy of C activity and D activity to stack.So whenever you press back button your flow look like this D [New Activity] ➜ C [New Activity ] ➜ E ➜ D [Old Activity] .So to overcome this issue here is the simple solution. First of all lets create HashMap static object with name of " screenStack ".   public static HashMap<String, Activity> screenStack; Now, create method addActivities() which add the activity in screenStack. // Add activity public static void addActivity(String activityName, Activity activity) {     if (Config.screenStack == null)         Config.screenStack = new HashMap<String, Activity>();     if (activity != null)   

How to increase the duration of toast message in android

I saw many questions regarding the increase in Toast duration. Many developer struggle with this even I also face this when I was new in android developing.So, Here are the two easy and fast techniques to increase the Toast duration. 1) Using For Loop : int duration = 7; for (int i = 0; i < duration; i++) {     Toast.makeText(Activity.this, "Hello", Toast.LENGTH_LONG).show(); } 2) Using CountDown Timer : /* Duration is in seconds.     If you wish to write something like this (7 * 1000). */ int duration = 7000; /* Duration is in seconds.     You can change the interval time according to your need.     Here we take interval of every one second. */ int interval = 1000; CountDownTimer countDownTimer = new CountDownTimer(duration, interval) {     @Override     public void onTick(long l)     {        Toast.makeText(Activity.this, "Hello", Toast.LENGTH_LONG).show();     }     @Override     public void onFinish() {     } }.start(); From the above both 1 and 2 code Toa

Getting started with android

Image
Before you start with coding lets download & install Android Studio .Over here you can find all the details regarding I nstallation , System Requirement, C ommand line tools etc. Now after the successful installation of android studio lets get started with simple Android application.     Create An Android Application After successful installation of android click on android studio.Sometime it takes some time to load depending on your system so, be patience.Once the android studio started it show screen like below. Now click on " Start a new Android Studio Project " and then you move to " Configure your new project " screen like below. Here it will ask you to enter  Application Name Package name (It will automatically taken from company domain) Project location (Your Project Directory where you want to save) Now we let us enter the application name as " FirstAndroidApp " then company domain "droid.com"