Saturday, 17 October 2015

How to find Android default screen orientation.

as i tried for the requirement of my personal project for getting default screen orientation.

i got the very simple solution taking int value

int orient=this.getResources().getConfiguration().orientation;

it will give the result either 1 or 2

1 is portrait and 2 is landscape

Friday, 2 October 2015

Auto logout after 15 minutes due to inactivity in android

create a service


ublic class LogoutService extends Service{
public static CountDownTimer timer;
private final String TAG="Service";
@Override
public void onCreate() {
// TODO Auto-generated method stub
super.onCreate();
timer = new CountDownTimer(1 *60 * 1000, 1000) {
           public void onTick(long millisUntilFinished) {
              //Some code
               Log.v(TAG, "Service Started");
           }

           public void onFinish() {
               Log.v(TAG, "Call Logout by Service");
               // Code for Logout
               stopSelf();
           }
        };
}



@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}

}


then add the code for all activity

@Override
protected void onResume() {
    // TODO Auto-generated method stub
    super.onResume();
    try {
    LogoutService.timer.start();
} catch (Exception e) {
e.printStackTrace();
}
   
}

@Override
protected void onStop() {
    // TODO Auto-generated method stub
    super.onStop();
    LogoutService.timer.cancel();
}   


here after certain minutes the first page will be displayed automatically