I am installing this application on the said tablet and I intend to supply this tablet to my client for a day or two, what I want is:
After checking the operations, the client should not be able to use the said application after the expiry date. for this I am calling the calander function and comparing the extracted system date (Day) with a day I want the application to close operation. I am using the following code:
public void expire(){
Calendar c = Calendar.getInstance();
int sDate = c.get(Calendar.YEAR);
int sMonth = c.get(Calendar.MONTH)+1;
int sDay = c.get(Calendar.DAY_OF_MONTH);
int sHour = c.get(Calendar.HOUR_OF_DAY);
int sMin = c.get(Calendar.MINUTE);
Toast.makeText(getApplicationContext(), ""+sDate+sMonth+sDay+"Hour is"+sHour, Toast.LENGTH_LONG).show();
if (sDay >=11){
System.exit(0);
}
}
I call expire(); on a button click to check, but all I get is a blank black screen for a few seconds and then the application works fine. Which I do not want.
Using finish() seemed to be working on the emulator after I called expire(); from the onCreate and not on button Click. However using System.exit(0) on a real device did help while as finish() did not.
System.exit() (In pure and core Java) can be used to run shutdown hooks before the program quits. This is a convenient way to handle shutdown in bigger programs, where all parts of the program can’t (and shouldn’t) be aware of each other. Then, if someone wants to quit, he can simply call System.exit(), and the shutdown hooks (if properly set up) take care of doing all necessary shutdown ceremonies such as closing files, releasing resources.
While as in case of finish() The method that called finish() will run to completion. The finish() operation will not even begin until you return control to Android.