0

I am trying to manage sessions in Android. I am using Shared Preferences to store the user data. The problem arises when any user logs in perfectly and the home page of my app should get open now, but the Logcat displays the error that there is no activity to handle this page.
Here is the code for Login.java.

public class Login extends Activity {
    Button but;
    TextView tex,tex2;
    EditText nameEdit,passEdit;

    public static final String MyPREFERENCES = "MyPrefs" ;
       public static final String name = "nameKey"; 
       public static final String pass = "passwordKey"; 
       SharedPreferences sharedpreferences;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);
    but=(Button)findViewById(R.id.login);

 // nameEdit, passEdit get the user entered username and password respectively.
    nameEdit = (EditText)findViewById(R.id.editText1);
    passEdit = (EditText)findViewById(R.id.editText2);

but.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {

//storing userdetails in Shared Preference
         Editor editor = sharedpreferences.edit();
              String u = nameEdit.getText().toString();
              String p = passEdit.getText().toString();
              editor.putString(name, u);
              editor.putString(pass, p);
              editor.commit();
             Intent openStartingPoint=new Intent("app.something.com.Menu");
            startActivity(openStartingPoint); //here occurs the error no activity found to handle this
            finish();
            return;

        }
    });
}    
   @Override
   protected void onResume() {

 //if user already logged in then direct him to "Menu".
      sharedpreferences=getSharedPreferences(MyPREFERENCES, Context.MODE_PRIVATE);
      if (sharedpreferences.contains(name))
      {
      if(sharedpreferences.contains(pass)){
         Intent i = new Intent("app.something.com.Menu");  
         startActivity(i);     
      }
      }
      super.onResume();
   }
}

The method to logout the user is following in which shared preference editor is cleared

   public void logout()
   {
    SharedPreferences sharedpreferences = getSharedPreferences(Login.MyPREFERENCES,Context.MODE_PRIVATE);
    Editor editor = sharedpreferences.edit();
    editor.clear();
    editor.commit();
    moveTaskToBack(true);
    Control_panel.this.finish();                            
    return;
   }

And this is the Manifest code:

<activity
        android:screenOrientation="portrait"
        android:name="app.something.com.Login"
        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="app.something.com.Menu"
     android:label="@string/app_name" >
        <intent-filter>
            <action android:name="app.something.com.Menu" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
  </activity>

I don't know why I am getting the ActivityNotFoundException even though the file Menu.java extends Activity class and is mentioned in the Manifest as well. After this Runtime exception when I start my app again, then I am taken directly to activity corresponding to Menu.java which is exactly what should happen. But the exception occurs only when somebody tries to login.
Please help me out!!
Thanks in advance :)

ankul09jain
  • 53
  • 1
  • 5

1 Answers1

0

The intent to open/launch another activity is like

Intent launchAnotherActivity = new Intent(CurrentActivity.this, 
                                             AnotherActivity.class);
startActivity(launchAnotherActivity);

So, I don't think what you have written is correct.

Rachit Mishra
  • 6,101
  • 4
  • 30
  • 51