Reputation: 7376
I searched this and found many solutions but none of them works for me .
I want to start new activity from another package. I use this
Intent myIntent = new Intent(this,my_class.class);
startActivityForResult(myIntent ,6161);
it gives this error:
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.xx.yy.pack/com.xx.yy.pack.my_class}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2305)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363)
at android.app.ActivityThread.access$900(ActivityThread.java:161)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1265)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5356)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at java.io.File.fixSlashes(File.java:185)
at java.io.File.<init>(File.java:134)
at com.wub.cropimage.CropImage.a(Unknown Source)
at com.wub.cropimage.CropImage.onCreate(Unknown Source)
at android.app.Activity.performCreate(Activity.java:5426)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2269)
... 11 more
my manifest is here:
<activity
android:name="com.xx.yy.pack.my_class" >
<intent-filter>
<action android:name="myintent.intent.action.Launch" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
thanks in advance
Upvotes: 0
Views: 307
Reputation: 406
Just do this
Intent myIntent = new Intent(this,my_class.class);
startActivity(myIntent);
Do this in your AndroidManifest.xml
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="Activity1"
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="com.example.Activity2"></activity>
</application>
Note:- Activity1 is your first activity and Activity2 is your second activity May this help you
Upvotes: 1
Reputation: 8510
To call an activity from another package (application):
Intent myIntent = new Intent(Intent.ACTION_MAIN);
PackageManager manager = getApplicationContext().getPackageManager();
myIntent = manager.getLaunchIntentForPackage(YourPackageName);
myIntent.addCategory(Intent.CATEGORY_LAUNCHER);
startActivityForResult(myIntent ,6161);
Upvotes: 0