Stop application from running in the background in android development

You need to override the onStop method which is called whenever the application goes in the background. Beware you need to add this to all your activities or it will only stop for that particular  activity.

public void onStop(){

How to disable orientation change (i.e only Landscape mode or only potrait mode) in android

If you want your android app not to change orientation when the user changes the orientation.

You can do it both programatically or updating the manifest file.

1) Updating the Manifest.

Just add this line to the activity that you want for a particular activity


It would look like 

Android Screen Display on your Mac, PC live

1. Go to the DDMS file in your tools page.
2. Your device should be connected to the PC and make sure you have the USB Debugging feature on.
3.  There you will see your device. Just double click on it and BOOM!! your screen appears in realtime on your PC.

Does not work for new devices. Instead use
Software called Screencast provided by android. If your phone is rooted then you can even control it through your


Android Toast (From the Activity as well as from outside the Activity)

  • If you want to add a Toast inside your Activity code then use this
       //Displays Toast for a short period of time
        Toast.makeText(getApplicationContext(),”Message you want to display”, Toast.LENGTH_SHORT).show();
        //Displays Toast for a longer period of time
        Toast.makeText(getApplicationContext(),”Message you want to display”, Toast.LENGTH_LONG).show();
  • There might be cases when you want to reuse your code for Toast notifications and want the code in a separate file that is called by different properties.
            In this case get this toast code in the separate file
            public static void toasty(Context con, String msg)



Toast.makeText(con, msg, Toast.LENGTH_LONG).show();


Call this method from your activities to reuse the code. Here AppUtilities is the class name where our                                                                                                                    method is written.

AppUtilies.toasty(getApplicationContext(), “Please enter an email and password”);