title: how to call one library activity from other library activity?
body: <p>I didn't had any other way to ask this question, So here is my problem:
  I have a library project that I use for two applications and its working well. Now I have common login page and login functionality for both the applications and to avoid duplicating the code I want to use same login activity for both the applications. here is code that I use</p>
  
  <p>library project</p>
  
  <pre><code>     public class CanteenPreference {
  
          // Static variables declaration
          private static final String KEY_INSTANCE_URL = "instance_url";
          private static final String KEY_USER_NAME = "user_name_preferences";
          private static final String KEY_ACCESS_KEY = "access_key_preferences";
          public static final String DEFAULT_URL = "some url";
          private static final String URL_SUFFIX = "/api/call";
  
          /**
           * Gets the preferred url.
           * 
           * @param activity
           * @return
           */
          public static String getUrl(Activity activity){
              SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(activity.getApplicationContext());
              String previousURL = sharedPrefs.getString(KEY_INSTANCE_URL, null);
              if (previousURL == null) {
                  Intent in=new Intent(activity,LoginActivity.class);
                  activity.startActivity(in);
  
                  previousURL = sharedPrefs.getString(KEY_INSTANCE_URL, DEFAULT_URL + URL_SUFFIX);
              }
              return previousURL;
          }
  
          /**
           * Gets the preferred user name.
           * 
           * @param activity
           * @return
           */
          public static String getUserName(Activity activity){
              SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(activity.getApplicationContext());
              String previousUsername = sharedPrefs.getString(KEY_USER_NAME, null);
              if (previousUsername == null) {
                  activity.startActivity(new Intent(activity, LoginActivity.class));
  
                  previousUsername = sharedPrefs.getString(KEY_USER_NAME, "test");
              }
              return previousUsername;
          }
  
          /**
           * Gets the preferred password.
           * 
           * @param activity
           * @return
           */
          public static String getPassword(Activity activity){
              SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(activity.getApplicationContext());
              String previousPassword = sharedPrefs.getString(KEY_ACCESS_KEY, null);
              if (previousPassword == null) {
                  activity.startActivity(new Intent(activity, LoginActivity.class));
  
                  previousPassword = sharedPrefs.getString(KEY_ACCESS_KEY, "test");
              }
              return previousPassword;
          }
  
          /**
           * Writes the preferences
           * 
           * @param activity
           * @param url
           * @param userName
           * @param password
           * @return true if committed
           */
          public static boolean write(Activity activity, String url, String userName, String password){
              SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(activity.getApplicationContext());
              SharedPreferences.Editor prefEditor = sharedPrefs.edit();
  
              prefEditor.putString(KEY_INSTANCE_URL, url + URL_SUFFIX);
              prefEditor.putString(KEY_USER_NAME, userName);
              prefEditor.putString(KEY_ACCESS_KEY, password);
              return prefEditor.commit();
          }
      }
  </code></pre>
  
  <p>and loginactivity in library</p>
  
  <pre><code> public class LoginActivity extends Activity {
      private EditText mUrlInput;
      private EditText mUserInput;
      private EditText mPasswordInput;
      private Button mButton;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.login_page);
          mButton = (Button) findViewById(R.id.loginButt);
          mUrlInput = (EditText) findViewById(R.id.urlInput);
          mUserInput = (EditText) findViewById(R.id.userInput);
          mPasswordInput = (EditText) findViewById(R.id.passwordInput);
  
          mUrlInput.setText(CanteenPreference.DEFAULT_URL);
  
          mButton.setOnClickListener(new OnClickListener() {
              public void onClick(View v) {
                  final String url = mUrlInput.getText().toString();
                  final String userName = mUserInput.getText().toString();
                  final String password = mPasswordInput.getText().toString();
  
                  if (url == null || url.length() == 0 || userName == null
                          || userName.length() == 0 || password == null
                          || password.length() == 0) {
                      Toast toast = Toast.makeText(LoginActivity.this,
                              "All fields are required", Toast.LENGTH_SHORT);
                      toast.show();
  
                  } else {
  
                      Thread loginThread = new Thread() {
                          @Override
                          public void run() {
                              try {
                                  DefaultHttpClient httpClient = new DefaultHttpClient();
                                  HttpPost httpPost = new HttpPost(url);
                                  List&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;();
  
                                  nameValuePairs.add(new BasicNameValuePair(
                                          "username", userName));
                                  nameValuePairs.add(new BasicNameValuePair(
                                          "password", password));
  
                                  httpPost.setEntity(new UrlEncodedFormEntity(
                                          nameValuePairs));
                                  HttpResponse httpResponse = httpClient
                                          .execute(httpPost);
  
                                  if (httpResponse.getStatusLine()
                                          .getStatusCode() != HttpStatus.SC_OK) {
                                      throw new Exception("Invalid credentials !");
                                  }
  
                              } catch (Exception e) {
                                  Log.d("Login: ", "Invalid credentials", e);
                                  Toast toast = Toast.makeText(
                                          LoginActivity.this,
                                          "Invalid credentials",
                                          Toast.LENGTH_SHORT);
                                  toast.show();
                              }
                              // write the preferences
                              CanteenPreference.write(LoginActivity.this, url,
                                      userName, password);
                              // finish the activity
                              LoginActivity.this.finish();
                          }
                      };
  
                      loginThread.start();
                  }
              }
          });
      }
  }
  </code></pre>
  
  <p>I have defined Login activity in both application and library manifest still I get following logcat`</p>
  
  <pre><code>    09-07 16:00:12.436: W/ActivityThread(1429): Application com.jumbybay.ferry is waiting for the debugger on port 8100...
  09-07 16:00:12.465: I/System.out(1429): Sending WAIT chunk
  09-07 16:00:12.465: I/dalvikvm(1429): Debugger is active
  09-07 16:00:12.476: I/System.out(1429): Debugger has connected
  09-07 16:00:12.476: I/System.out(1429): waiting for debugger to settle...
  09-07 16:00:12.685: I/System.out(1429): waiting for debugger to settle...
  09-07 16:00:12.836: I/dalvikvm(1429): threadid=3: reacting to signal 3
  09-07 16:00:12.896: I/System.out(1429): waiting for debugger to settle...
  09-07 16:00:12.896: I/dalvikvm(1429): Wrote stack traces to '/data/anr/traces.txt'
  09-07 16:00:13.096: I/System.out(1429): waiting for debugger to settle...
  09-07 16:00:13.306: I/System.out(1429): waiting for debugger to settle...
  09-07 16:00:13.336: I/dalvikvm(1429): threadid=3: reacting to signal 3
  09-07 16:00:13.346: I/dalvikvm(1429): Wrote stack traces to '/data/anr/traces.txt'
  09-07 16:00:13.505: I/System.out(1429): waiting for debugger to settle...
  09-07 16:00:13.708: I/System.out(1429): waiting for debugger to settle...
  09-07 16:00:13.836: I/dalvikvm(1429): threadid=3: reacting to signal 3
  09-07 16:00:13.856: I/dalvikvm(1429): Wrote stack traces to '/data/anr/traces.txt'
  09-07 16:00:13.906: I/System.out(1429): waiting for debugger to settle...
  09-07 16:00:14.106: I/System.out(1429): waiting for debugger to settle...
  09-07 16:00:14.306: I/System.out(1429): waiting for debugger to settle...
  09-07 16:00:14.376: I/dalvikvm(1429): threadid=3: reacting to signal 3
  09-07 16:00:14.385: I/dalvikvm(1429): Wrote stack traces to '/data/anr/traces.txt'
  09-07 16:00:14.515: I/System.out(1429): waiting for debugger to settle...
  09-07 16:00:14.717: I/System.out(1429): waiting for debugger to settle...
  09-07 16:00:14.846: I/dalvikvm(1429): threadid=3: reacting to signal 3
  09-07 16:00:14.866: I/dalvikvm(1429): Wrote stack traces to '/data/anr/traces.txt'
  09-07 16:00:14.916: I/System.out(1429): debugger has settled (1325)
  09-07 16:00:15.356: I/dalvikvm(1429): threadid=3: reacting to signal 3
  09-07 16:00:15.375: I/dalvikvm(1429): Wrote stack traces to '/data/anr/traces.txt'
  09-07 16:00:15.866: I/dalvikvm(1429): threadid=3: reacting to signal 3
  09-07 16:00:15.886: D/dalvikvm(1429): threadid=1: still suspended after undo (sc=1 dc=1)
  09-07 16:00:15.886: I/dalvikvm(1429): Wrote stack traces to '/data/anr/traces.txt'
  09-07 16:00:16.375: I/dalvikvm(1429): threadid=3: reacting to signal 3
  09-07 16:00:16.385: D/dalvikvm(1429): threadid=1: still suspended after undo (sc=1 dc=1)
  09-07 16:00:16.385: I/dalvikvm(1429): Wrote stack traces to '/data/anr/traces.txt'
  09-07 16:00:16.866: I/dalvikvm(1429): threadid=3: reacting to signal 3
  09-07 16:00:16.876: D/dalvikvm(1429): threadid=1: still suspended after undo (sc=1 dc=1)
  09-07 16:00:16.886: I/dalvikvm(1429): Wrote stack traces to '/data/anr/traces.txt'
  09-07 16:00:17.375: I/dalvikvm(1429): threadid=3: reacting to signal 3
  09-07 16:00:17.385: D/dalvikvm(1429): threadid=1: still suspended after undo (sc=1 dc=1)
  09-07 16:00:17.385: I/dalvikvm(1429): Wrote stack traces to '/data/anr/traces.txt'
  09-07 16:00:17.886: I/dalvikvm(1429): threadid=3: reacting to signal 3
  09-07 16:00:17.896: D/dalvikvm(1429): threadid=1: still suspended after undo (sc=1 dc=1)
  09-07 16:00:17.896: I/dalvikvm(1429): Wrote stack traces to '/data/anr/traces.txt'
  09-07 16:00:18.385: I/dalvikvm(1429): threadid=3: reacting to signal 3
  09-07 16:00:18.395: D/dalvikvm(1429): threadid=1: still suspended after undo (sc=1 dc=1)
  09-07 16:00:18.395: I/dalvikvm(1429): Wrote stack traces to '/data/anr/traces.txt'
  09-07 16:00:18.896: I/dalvikvm(1429): threadid=3: reacting to signal 3
  09-07 16:00:18.906: D/dalvikvm(1429): threadid=1: still suspended after undo (sc=1 dc=1)
  09-07 16:00:18.906: I/dalvikvm(1429): Wrote stack traces to '/data/anr/traces.txt'
  09-07 16:00:19.395: I/dalvikvm(1429): threadid=3: reacting to signal 3
  09-07 16:00:19.405: D/dalvikvm(1429): threadid=1: still suspended after undo (sc=1 dc=1)
  09-07 16:00:19.405: I/dalvikvm(1429): Wrote stack traces to '/data/anr/traces.txt'
  09-07 16:00:19.896: I/dalvikvm(1429): threadid=3: reacting to signal 3
  09-07 16:00:19.916: D/dalvikvm(1429): threadid=1: still suspended after undo (sc=1 dc=1)
  09-07 16:00:19.916: I/dalvikvm(1429): Wrote stack traces to '/data/anr/traces.txt'
  09-07 16:00:20.395: I/dalvikvm(1429): threadid=3: reacting to signal 3
  09-07 16:00:20.415: D/dalvikvm(1429): threadid=1: still suspended after undo (sc=1 dc=1)
  09-07 16:00:20.415: I/dalvikvm(1429): Wrote stack traces to '/data/anr/traces.txt'
  09-07 16:00:20.906: I/dalvikvm(1429): threadid=3: reacting to signal 3
  09-07 16:00:20.926: D/dalvikvm(1429): threadid=1: still suspended after undo (sc=1 dc=1)
  09-07 16:00:20.926: I/dalvikvm(1429): Wrote stack traces to '/data/anr/traces.txt'
  09-07 16:00:21.405: I/dalvikvm(1429): threadid=3: reacting to signal 3
  09-07 16:00:21.425: D/dalvikvm(1429): threadid=1: still suspended after undo (sc=1 dc=1)
  09-07 16:00:21.425: I/dalvikvm(1429): Wrote stack traces to '/data/anr/traces.txt'
  09-07 16:00:21.916: I/dalvikvm(1429): threadid=3: reacting to signal 3
  09-07 16:00:21.926: D/dalvikvm(1429): threadid=1: still suspended after undo (sc=1 dc=1)
  09-07 16:00:21.936: I/dalvikvm(1429): Wrote stack traces to '/data/anr/traces.txt'
  09-07 16:01:15.126: W/ActivityThread(1470): Application com.jumbybay.ferry is waiting for the debugger on port 8100...
  09-07 16:01:15.176: I/System.out(1470): Sending WAIT chunk
  09-07 16:01:15.176: I/dalvikvm(1470): Debugger is active
  09-07 16:01:15.385: I/System.out(1470): Debugger has connected
  09-07 16:01:15.385: I/System.out(1470): waiting for debugger to settle...
  09-07 16:01:15.585: I/System.out(1470): waiting for debugger to settle...
  09-07 16:01:15.787: I/System.out(1470): waiting for debugger to settle...
  09-07 16:01:15.996: I/System.out(1470): waiting for debugger to settle...
  09-07 16:01:16.195: I/System.out(1470): waiting for debugger to settle...
  09-07 16:01:16.399: I/System.out(1470): waiting for debugger to settle...
  09-07 16:01:16.601: I/System.out(1470): waiting for debugger to settle...
  09-07 16:01:16.795: I/System.out(1470): waiting for debugger to settle...
  09-07 16:01:16.996: I/System.out(1470): waiting for debugger to settle...
  09-07 16:01:17.207: I/System.out(1470): waiting for debugger to settle...
  09-07 16:01:17.408: I/System.out(1470): waiting for debugger to settle...
  09-07 16:01:17.610: I/System.out(1470): debugger has settled (1403)
  09-07 16:02:10.908: D/AndroidRuntime(1470): Shutting down VM
  09-07 16:02:10.908: W/dalvikvm(1470): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
  09-07 16:02:11.056: E/AndroidRuntime(1470): FATAL EXCEPTION: main
  09-07 16:02:11.056: E/AndroidRuntime(1470): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.jumbybay.ferry/com.jumbybay.ferry.FerryMain}: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.jumbybay.ferry/com.jumbybay.activity.LoginActivity}; have you declared this activity in your AndroidManifest.xml?
  09-07 16:02:11.056: E/AndroidRuntime(1470):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
  09-07 16:02:11.056: E/AndroidRuntime(1470):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
  09-07 16:02:11.056: E/AndroidRuntime(1470):     at android.app.ActivityThread.access$600(ActivityThread.java:123)
  09-07 16:02:11.056: E/AndroidRuntime(1470):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
  09-07 16:02:11.056: E/AndroidRuntime(1470):     at android.os.Handler.dispatchMessage(Handler.java:99)
  09-07 16:02:11.056: E/AndroidRuntime(1470):     at android.os.Looper.loop(Looper.java:137)
  09-07 16:02:11.056: E/AndroidRuntime(1470):     at android.app.ActivityThread.main(ActivityThread.java:4424)
  09-07 16:02:11.056: E/AndroidRuntime(1470):     at java.lang.reflect.Method.invokeNative(Native Method)
  09-07 16:02:11.056: E/AndroidRuntime(1470):     at java.lang.reflect.Method.invoke(Method.java:511)
  09-07 16:02:11.056: E/AndroidRuntime(1470):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
  09-07 16:02:11.056: E/AndroidRuntime(1470):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
  09-07 16:02:11.056: E/AndroidRuntime(1470):     at dalvik.system.NativeStart.main(Native Method)
  09-07 16:02:11.056: E/AndroidRuntime(1470): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.jumbybay.ferry/com.jumbybay.activity.LoginActivity}; have you declared this activity in your AndroidManifest.xml?
  09-07 16:02:11.056: E/AndroidRuntime(1470):     at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1508)
  09-07 16:02:11.056: E/AndroidRuntime(1470):     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1384)
  09-07 16:02:11.056: E/AndroidRuntime(1470):     at android.app.Activity.startActivityForResult(Activity.java:3190)
  09-07 16:02:11.056: E/AndroidRuntime(1470):     at android.app.Activity.startActivity(Activity.java:3297)
  09-07 16:02:11.056: E/AndroidRuntime(1470):     at com.jumbybay.activity.CanteenPreference.getUrl(CanteenPreference.java:32)
  09-07 16:02:11.056: E/AndroidRuntime(1470):     at com.jumbybay.ferry.FerryMain.onCreate(FerryMain.java:42)
  09-07 16:02:11.056: E/AndroidRuntime(1470):     at android.app.Activity.performCreate(Activity.java:4465)
  09-07 16:02:11.056: E/AndroidRuntime(1470):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
  09-07 16:02:11.056: E/AndroidRuntime(1470):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
  09-07 16:02:11.056: E/AndroidRuntime(1470):     ... 11 more
  09-07 16:02:11.716: I/dalvikvm(1470): threadid=3: reacting to signal 3
  09-07 16:02:11.736: I/dalvikvm(1470): Wrote stack traces to '/data/anr/traces.txt'
  09-07 16:07:11.416: I/Process(1470): Sending signal. PID: 1470 SIG: 9
  </code></pre>
  
  <p>manifest file main activity</p>
  
  <pre><code>        &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.jumbybay.ferry"
          android:versionCode="1"
          android:versionName="1.0" &gt;
  
          &lt;uses-sdk
              android:minSdkVersion="11"
              android:targetSdkVersion="10" /&gt;
  
          &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
          &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt;
  
          &lt;application
              android:icon="@drawable/ic_launcher"
              android:label="@string/app_name"
              android:theme="@style/AppTheme" &gt;
              &lt;activity android:name=".FerryMain" &gt;
                  &lt;intent-filter&gt;
                      &lt;action android:name="android.intent.action.MAIN" /&gt;
  
                      &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
                  &lt;/intent-filter&gt;
              &lt;/activity&gt;
  
              &lt;activity android:name=".ferryBlur" &gt;
              &lt;/activity&gt;
              &lt;activity android:name=".PassengerList" &gt;
              &lt;/activity&gt;
              &lt;activity android:name=".com.jumbybay.activity.LoginActivity" &gt;
              &lt;/activity&gt;
              &lt;activity android:name=".TripIn" &gt;
              &lt;/activity&gt;
          &lt;/application&gt;
  
      &lt;/manifest&gt;
  </code></pre>
  
  <p>manifest file library</p>
  
  <pre><code>    &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.jumbybay.activity"
      android:versionCode="1"
      android:versionName="1.0" &gt;
  
      &lt;uses-sdk
          android:minSdkVersion="14"
          android:targetSdkVersion="15" /&gt;
  
      &lt;uses-permission android:name="android.permission.NFC" /&gt;
          &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
  
      &lt;uses-feature android:name="android.hardware.nfc" /&gt;
  
      &lt;application&gt;
          &lt;activity
              android:name=".LoginActivity"
              android:label="Jumbybay : Canteen" &gt;
          &lt;/activity&gt;
          &lt;activity android:name=".NfcReaderActivity" &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.nfc.action.TAG_DISCOVERED" /&gt;
  
                  &lt;category android:name="android.intent.category.DEFAULT" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>