
End session after 5 min when APP INACTIVE or pressed home button - android
- or -
Post a project like this3556
$10
- Posted:
- Proposals: 1
- Remote
- #1102121
- Awarded
Description
Experience Level: Intermediate
General information for the app: I want this is script for secure data from other
Kind of development: Customization of existing app
Description of requirements/features: I USED AS BELOW
public class LogoutService extends Service {
public static CountDownTimer timer;
@Override
public void onCreate() {
// TODO Auto-generated method stub
super.onCreate();
timer = new CountDownTimer(1, 1000) {//1 * 60 * 1000, 1000
public void onTick(long millisUntilFinished) {
//Some code
// Log.v(Constants.TAG, "Service Started");
}
public void onFinish() {
// Log.v(SyncStateContract.Constants.TAG, "Call Logout by Service");
// Code for Logout
dialogBox();
Log.i("fr","fr");
stopSelf();
}
};
}
public void dialogBox() {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
alertDialogBuilder.setMessage("Your session has expired.");
alertDialogBuilder.setPositiveButton("Ok",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
}
});
// alertDialogBuilder.setNegativeButton("cancel",
// new DialogInterface.OnClickListener() {
//
// @Override
// public void onClick(DialogInterface arg0, int arg1) {
//
// }
// });
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
}
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
}
how to code end session after(logout) 5 min when android APP INACTIVE or pressed home button? i have used below code...... that for keep data on save.....................................................................
public class LogoutService extends Service {
public static CountDownTimer timer;
@Override
public void onCreate() {
// TODO Auto-generated method stub
super.onCreate();
timer = new CountDownTimer(1, 1000) {//1 * 60 * 1000, 1000
public void onTick(long millisUntilFinished) {
//Some code
// Log.v(Constants.TAG, "Service Started");
}
public void onFinish() {
// Log.v(SyncStateContract.Constants.TAG, "Call Logout by Service");
// Code for Logout
dialogBox();
Log.i("fr","fr");
stopSelf();
}
};
}
public void dialogBox() {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
alertDialogBuilder.setMessage("Your session has expired.");
alertDialogBuilder.setPositiveButton("Ok",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
}
});
// alertDialogBuilder.setNegativeButton("cancel",
// new DialogInterface.OnClickListener() {
//
// @Override
// public void onClick(DialogInterface arg0, int arg1) {
//
// }
// });
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
}
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
}
on MainActivity:
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
LogoutService.timer.start();
}
@Override
protected void onStop() {
// TODO Auto-generated method stub
super.onStop();
LogoutService.timer.cancel();
}
the error:
3-28 01:52:12.381 1250-1250/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com. . ., PID: 1250
java.lang.NullPointerException
Extra notes:
Kind of development: Customization of existing app
Description of requirements/features: I USED AS BELOW
public class LogoutService extends Service {
public static CountDownTimer timer;
@Override
public void onCreate() {
// TODO Auto-generated method stub
super.onCreate();
timer = new CountDownTimer(1, 1000) {//1 * 60 * 1000, 1000
public void onTick(long millisUntilFinished) {
//Some code
// Log.v(Constants.TAG, "Service Started");
}
public void onFinish() {
// Log.v(SyncStateContract.Constants.TAG, "Call Logout by Service");
// Code for Logout
dialogBox();
Log.i("fr","fr");
stopSelf();
}
};
}
public void dialogBox() {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
alertDialogBuilder.setMessage("Your session has expired.");
alertDialogBuilder.setPositiveButton("Ok",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
}
});
// alertDialogBuilder.setNegativeButton("cancel",
// new DialogInterface.OnClickListener() {
//
// @Override
// public void onClick(DialogInterface arg0, int arg1) {
//
// }
// });
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
}
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
}
how to code end session after(logout) 5 min when android APP INACTIVE or pressed home button? i have used below code...... that for keep data on save.....................................................................
public class LogoutService extends Service {
public static CountDownTimer timer;
@Override
public void onCreate() {
// TODO Auto-generated method stub
super.onCreate();
timer = new CountDownTimer(1, 1000) {//1 * 60 * 1000, 1000
public void onTick(long millisUntilFinished) {
//Some code
// Log.v(Constants.TAG, "Service Started");
}
public void onFinish() {
// Log.v(SyncStateContract.Constants.TAG, "Call Logout by Service");
// Code for Logout
dialogBox();
Log.i("fr","fr");
stopSelf();
}
};
}
public void dialogBox() {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
alertDialogBuilder.setMessage("Your session has expired.");
alertDialogBuilder.setPositiveButton("Ok",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
}
});
// alertDialogBuilder.setNegativeButton("cancel",
// new DialogInterface.OnClickListener() {
//
// @Override
// public void onClick(DialogInterface arg0, int arg1) {
//
// }
// });
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
}
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
}
on MainActivity:
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
LogoutService.timer.start();
}
@Override
protected void onStop() {
// TODO Auto-generated method stub
super.onStop();
LogoutService.timer.cancel();
}
the error:
3-28 01:52:12.381 1250-1250/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com. . ., PID: 1250
java.lang.NullPointerException
Extra notes:
Abeer S.
100% (3)Projects Completed
6
Freelancers worked with
4
Projects awarded
29%
Last project
14 Apr 2016
Saudi Arabia
New Proposal
Login to your account and send a proposal now to get this project.
Log inClarification Board Ask a Question
-
There are no clarification messages.
We collect cookies to enable the proper functioning and security of our website, and to enhance your experience. By clicking on 'Accept All Cookies', you consent to the use of these cookies. You can change your 'Cookies Settings' at any time. For more information, please read ourCookie Policy
Cookie Settings
Accept All Cookies