Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I had similar problem in one of my application; But i got the solution. The problem is, the boolean you have defined isloggingout in your class, it resets after you close your application. Its a variable which stores your value until your application is open. As soon as you close your application it gets reset and your application wont work.. I will suggest you to use Sharedpreference to store that value..</p> <p>Good luck</p> <p>Updates with example application:</p> <p><b>MainActivity.java</b></p> <pre><code> public class MainActivity extends Activity { SharedPreferences SM; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.loginpage); SM = getSharedPreferences("userrecord", 0); Boolean islogin = SM.getBoolean("userlogin", false); if(islogin){ Intent intent = new Intent(MainActivity.this, Dashboard.class); startActivity(intent); finish(); return; } Button login = (Button) findViewById(R.id.login); final EditText ETuser = (EditText) findViewById(R.id.editText1); final EditText ETpass = (EditText) findViewById(R.id.editText2); login.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { String user = ETuser.getText().toString(); String pass = ETpass.getText().toString(); if(user.equalsIgnoreCase("admin") &amp;&amp; pass.equalsIgnoreCase("admin")){ Editor edit = SM.edit(); edit.putBoolean("userlogin", true); edit.commit(); Intent intent = new Intent(MainActivity.this, Dashboard.class); startActivity(intent); finish(); }else{ Toast.makeText(getApplicationContext(), "Username/Password Invalid", Toast.LENGTH_LONG).show(); } } }); } } </code></pre> <p><b>Dashboard.java</b></p> <pre><code>public class Dashboard extends Activity{ @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button logout = (Button) findViewById(R.id.logout); logout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { SharedPreferences SM = getSharedPreferences("userrecord", 0); Editor edit = SM.edit(); edit.putBoolean("userlogin", false); edit.commit(); Intent intent = new Intent(Dashboard.this, MainActivity.class); startActivity(intent); finish(); } }); } } </code></pre> <p><b>loginpage.xml</b></p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:padding="10dp" &gt; &lt;EditText android:id="@+id/editText1" android:layout_width="match_parent" android:layout_height="wrap_content" android:ems="10" &gt; &lt;requestFocus /&gt; &lt;/EditText&gt; &lt;EditText android:id="@+id/editText2" android:layout_width="match_parent" android:layout_height="wrap_content" android:ems="10" android:inputType="textPassword" /&gt; &lt;Button android:id="@+id/login" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="login" /&gt; &lt;/LinearLayout&gt; </code></pre> <p><b>activity_main.xml</b></p> <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MainActivity" &gt; &lt;TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello User" /&gt; &lt;Button android:id="@+id/logout" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/textView1" android:layout_below="@+id/textView1" android:layout_marginLeft="50dp" android:layout_marginTop="57dp" android:text="Logout" /&gt; &lt;/RelativeLayout&gt; </code></pre> <p>Try this example and hope this will help you</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload