I have run the application using Splash activity screen for 5 seconds. Then open the Login activity screen , after you put the correct password and password, open Menu activity (listActivity) , then each line open MyCity activity .
UPDATE:
What I'm trying to get is: wherever you are in my application, and you leave my application for some reason, not only when you press the home button , but for examples:
You press the home button to check another application, and then return to my application.
You have a notification showing a new message about whatsup or email, you open your message or open an email, and then return to your application.
3. You left your mobile phone for a certain period of time, after which you want to check my application again.
4- press the power button to close the phone (lock the screen), then open the lock and want to return to my application.
what do I mean, when you leave my application for some reason, but without pressing the back button, which will exit the entire application, you want to return to my application again, you need to open the login screen to enter your username and password.
I called finish(); for splash activity and input activity.
I tried: android:clearTaskOnLaunch="true" in the activity of entering the manifest, but it does nothing.
Any advice would be appreciated,
PLEASE WRITE A FULL WORK CODE.
INPUT ACTIVITY:
public class Login extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.login); Button b = (Button) findViewById(R.id.loginbutton); b.setOnClickListener(new OnClickListener() { public void onClick(View v) { EditText username = (EditText) findViewById(R.id.login); EditText password = (EditText) findViewById(R.id.password); if(username.getText().toString().length() > 0 && password.getText(). toString().length() > 0 ) { if(username.getText().toString().equals("test") && password.getText(). toString().equals("test")) { Intent intent = new Intent(Login.this, Menu.class); startActivity(intent); finish(); } } } }); } }
Menu activity:
public class Menu extends ListActivity { String classes[] = { "City1", "City2", "City3", "City4", "City5"}; @Override protected void onCreate(Bundle savedInstanceState) {
MyCity Activity:
public class MyCity extends Activity { TextView tv1; String city; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.city); initializeTextViews();} private void initializeTextViews() { tv1=(TextView)findViewById(R.id.city_tv); city=getIntent().getStringExtra("cheese"); if(city.equalsIgnoreCase("City1")){ tv1.setText(Html.fromHtml(getString(R.string.city1)));} else if(city.equalsIgnoreCase("City2")){ tv1.setText(Html.fromHtml(getString(R.string.city2)));} else if(city.equalsIgnoreCase("City3")){ tv1.setText(Html.fromHtml(getString(R.string.city3)));} else if(city.equalsIgnoreCase("City4")){ tv1.setText(Html.fromHtml(getString(R.string.city4)));} else if(city.equalsIgnoreCase("City5")){ tv1.setText(Html.fromHtml(getString(R.string.city5)));} }}
MY MANIFEST:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.test.demo" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="15" /> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name=".Splash" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".Login" android:label="@string/app_name" android:clearTaskOnLaunch="true"> <intent-filter> <action android:name="com.test.demo.LOGIN" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity> <activity android:name=".Menu" android:label="@string/app_name" > <intent-filter> <action android:name="com.test.demo.MENU" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity> <activity android:name=".MyCity" android:label="@string/app_name" > <intent-filter> <action android:name="com.test.demo.MYCITY" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity> </application> </manifest>
SECOND UPDATE : I got to what I want, but still I can’t achieve some steps, as described below:
By applying android:clearTaskOnLaunch="true" to Splash activity,
and prevent the back button from working in the menu action:
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { moveTaskToBack(true); return true; } return super.onKeyDown(keyCode, event); } }
SO now when you press the home button from my application, and then return to your application:
Go directly to login activity .
but the main goal now:
if:
THE SCREEN IS LOCKED when you are away from your mobile phone, or press the power button lightly to lock the phone.
or
OPEN MESSAGE NOTIFICATIONS
or
OPEN EMAIL NOTIFICATIONS
or
you have a call and answer it,
THEN return my application , it does not switch to login activity , but you will return to the page where you were.
ANY ADVICE PLEASE THANKS.
THIED UPDATE:
I used different code to override the home button and controlled the back button, not the application: android:clearTaskOnLaunch="true" to activate the activity in the manifest, just apply the code down to the menu activity:
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { moveTaskToBack(true); return true;} else if (keyCode == KeyEvent.KEYCODE_HOME) { Intent i=new Intent(Menu.this,Login.class); startActivity(i); finish(); return true;} return super.onKeyDown(keyCode, event);}