I have read all of your requirements,you need to just manipulate the flow of application as I have shown below to achieve it.I hope it will be helpful to you.
Inside your login screen which is going to be launched while starting the application,
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
UTILS.Log_e(TAG, "onCreate");
initialize();
//check for configuration
//here you need to check,whether user has been logged in already or not
if(!CONSTANTS.isConfigured)
{
//display login dialog if user has not been logged in already
displayLoginDialog();
}
else
{
//move to Home screen if user has already logged in
i.setClass(mContext, HomeActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
finish();
}
}
Inside your Home screen,
@Override
public void onBackPressed() {
exitApp();
}
private void exitApp()
{
i.setClass(mContext, ExitActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
finish();
}
//call logout function as per your requirement
private void logout()
{
i.setClass(mContext, LoginActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
finish();
}
Inside your ExitActivity,
public class ExitActivity extends Activity{
private static final String TAG = "ExitActivity";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
moveTaskToBack(true);
finish();
}
}
NOTE:
in above codes, I have used i.setClass(context,destination_class_name)
in which i
is the instance of Intent
.
Inside your manifest,
<activity
android:name=".ui.LoginActivity"
android:label="@string/app_name"
android:windowSoftInputMode="stateHidden|adjustPan">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ui.HomeActivity" >
</activity>
<activity
android:name=".ui.ExitActivity" >
</activity>
Kindly let me know if you face any problems or if you don't understand any point in above code.