Skip to content Skip to sidebar Skip to footer

Calling Activities From Different Package

I have two activities from two different packages, I wish to call an activity in Package2 from package1 To do so i used the following, Intent intentDeviceTest = new Intent();

Solution 1:

I always use the second form in my apps. It is simpler, clearer and shorter.

// Assumes that this is done from within an Activity
Intent intent = newIntent(this, AnotherActivity.class);  
startActivity(intent);

But I think the problem with the first form is that you specified the package again in the second parameter. You only need the class name:

IntentintentDeviceTest=newIntent();                
intentDeviceTest.setComponent(newComponentName("chat.client.gui", "MainActivity"));
startActivity(intentDeviceTest);

Look at the first constructor in this for a reference: http://developer.android.com/reference/android/content/ComponentName.html

Post a Comment for "Calling Activities From Different Package"