how to reference classes from other package in Android? - android

I'd like to ask how to reference other classes from my other package in Android?
I have my main package. Under that it has several subpackages.
How do I reference those classes under subpackage into my main class in the main package?
What I'm doing is, in the main class, I'm calling the class in the subpackage via Intent.
Here's what I've tried so far to no avail:
case 0:
Intent acorn = new Intent( "com.fps.iHealthFirst.vegetables.AcornSquash.class" );
//Intent acorn = new Intent( Nutritional_List.this, AcornSquash.class );
startActivity( acorn );
break;
I'm having a hard time doing this. Thanks for your help.
BTW, this is the logcat:
10-22 23:13:03.585: E/AndroidRuntime(395): FATAL EXCEPTION: main
10-22 23:13:03.585: E/AndroidRuntime(395): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.fps.iHealthFirst/com.fps.iHealthFirst.vegetables.AcornSquash}; have you declared this activity in your AndroidManifest.xml?
Also, I've edited this in the manifest file:
<activity android:exported="false"
android:name=".vegetables.AcornSquashAcornSquash"
android:label="#string/inutrition" >
<intent-filter >
<action android:name="com.fps.iHealthFirst.vegetables.ACORNSQUASH" />
</intent-filter>
</activity>

Here is what you should do:
import com.fps.iHealthFirst.vegetables.AcornSquash;
Intent acorn = new Intent(this, AcornSquash.class);
startActivity(acorn);
UPDATE:
You have to declare all your activities in your Manifest.xml. Keep it simple:
<activity
android:name="com.fps.iHealthFirst.vegetables.AcornSquash"
android:label="#string/some_name" >
</activity>
Finally, make sure your folder structure is in line with your packages paths, i.e. your file AcornSquash.java has to be in the src/com/fps/iHealthFirst/vegetables/ folder.

you can try this:
Intent acorn = new Intent(Intent.ACTION_VIEW, "com.fps.iHealthFirst.vegetables.AcornSquash" );

Related

Unable to find explicit activity class, even when i declare the intent in the manifest

I have an activity which I declare in my manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.my">
<uses-sdk android:minSdkVersion="14"/>
<application>
<activity
android:name="com.my.InternalDummyActivity"
android:exported="false">
</activity>
</application>
</manifest>
I have tried without the exported=false as well
The application contains an inner library with another activity.
I try to call an explicit intent from the other activity (other namespace)
But I always get an exception:
Intent intent1 = new Intent(activity.getApplicationContext(), InternalDummyActivity.class);
activity.startActivity(intent1);
ComponentName componentName2 =
new ComponentName(
"com.my","com.my.InternalDummyActivity");
Intent intent2 = new Intent().setComponent(componentName2); //dones work
activity.startActivity(intent2);
Process: com.comp.outter, PID: 9267
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.my/com.my.InternalDummyActivity}; have you declared this activity in your AndroidManifest.xml?
How can I fix this?
Try using one of the ComponentName's contructors that uses a Context, such as
ComponentName cn = new ComponentName(context,
"com.my.InternalDummyActivity");
For some reason, you can use the contructor taking two Strings only if you know the class dynamically.
Also, update your manifest as follow:
<activity
android:name=".InternalDummyActivity">
</activity>
and application package name should be in lower case only, as mentioned in Java's Naming Conventions in Oracle Docs
Package names are written in all lower case to avoid conflict with the
names of classes or interfaces
This question is possible duplicate of the thread gives below
How to call activity from a library module in android studio
Check if this is what you are looking for.

ndroid.content.ActivityNotFoundException:

android.content.ActivityNotFoundException: Unable to find explicit activity class {com.myapp.videomodule/com.myapp.videomodule.VideoCallActivity}; have you declared this activity in your AndroidManifest.xml?
My app package is com.myapp.doctors
module package is com.myapp.videomodule
if(splitInstallManager.getInstalledModules().contains("videomodule")){
Intent intent = new Intent();
intent.setClassName("com.myapp.videomodule", "com.myapp.videomodule.VideoCallActivity");
startActivity(intent);
}
I have declared it in the manifest the thing is I am trying dymanic module delivery, so that videoactivity is in other module
It seems that dynamic feature modules are declared in base app package. (as you can verify using Merged Manifest feature on your module Manifest.xml
I suggest the following modification:
if(splitInstallManager.getInstalledModules().contains("videomodule")){
Intent intent = new Intent();
intent.setClassName(getPackageName(), "com.myapp.videomodule.VideoCallActivity");
startActivity(intent);
}
Go to manifests > AndroidManifest.xml > check if com.myapp.videomodule.VideoCallActivity is declared there, if not, put it like:
<manifest>
....
<application
...>
...
<activity
android:name="com.myapp.videomodule.VideoCallActivity"
android:label="#string/title_videocallactivity" your activity title
android:theme="#style/AppTheme.NoActionBar" />
...
</application>
</manifest>
Try starting the intent like this:
Intent intent = new Intent(this, VideoCallActivity.class);
startActivity(intent)

Sending explicit Intent to my Activity declared in my Android lib

I have a ADT app, myadtapp (myapppkg), uses an Android Lib, myadtlib (mylibpackage). Inside myadtlib project, I created a custom Activity, myjavapkg.MyActivity, and declare the Activity in MyAdtLib::AndroidManifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="mylibpackage" ... >
...
<application>
<activity
android:name="myjavapkg.MyActivity"
android:exported="true" />
...
I am surprised the following code doesn't work:
Intent intent = new Intent();
intent.setClassName("mylibpackage", MyActivity.class.getName());
startActivity(intent);
The error is:
ActivityNotFoundException: Unable to find explicit activity class {mylibpackage/myjavapkg.MyActivity}; have you declared this activity in your AndroidManifest.xml?
If I move MyActivity declartion to the myadtapp manifest file, it would work, but I don't want to. What is wrong with the above using an MyActivity in an my Android lib?
This should work:
Intent intent = new Intent(this, MyActivity.class);
startActivity(intent);

Issue starting an activity from a different package

Hi I currently have two packages in my android application say com.packagea and com.packageb .Now I am attempting to activate an activity in com.packageb from an activity in com.packagea by the following code
String username = ((android.widget.EditText)findViewById(R.id.editUserName)).getText().toString();
String pass = ((android.widget.EditText)findViewById(R.id.editPass)).getText().toString();
Intent i = new Intent(this, Authenticate.class);
i.putExtra("uname", username);
i.putExtra("pass",pass);
startActivityForResult(i, 1);
However it wont even go into Authenticate.class which is in com.packageb. Any suggestions why it isnt going in that class. Here is how I have declared the activity in my manifest file
<activity
android:name=".Authenticate"
android:label="#string/title_activity_options" >
</activity>
Do I need to specify a package name along with this. This only happens when I attempt to call an activity from a different package. Any suggestions on how to resolve this issue
If Authenticate activity is in com.packageb and you are trying to invoke it form com.packagea package you can use the ceonvenience method Intent.setClassName():
Intent i = new Intent();
i.setClassName("com.packageb", "com.packageb.Authenticate");
...
Try using the fully qualified name:
com.packageb.Authenticate
<activity
android:name="com.packageb.Authenticate"
android:label="#string/title_activity_options" >
</activity>
instead of
<activity
android:name=".Authenticate"
android:label="#string/title_activity_options" >
</activity>

How to link two activities in Android project

I just want to code for splashscreen. for that I used intent but I am getting error that instrumention source not found. I have two files splashscreen.java and myapps.java where I have use threading concept and called anothe activity as
finally
{
finish();
startActivity(new Intent("com.example.MyApps"));
stop();
}
# startAcitivy I am getting axception please guide me do I have to modify androidmanifest file? if yes please provide me syntax for that.
If you're starting a new Activity with intent, I prefer using it like:
Intent intent = new Intent(MyClass.this, MyApps.class);
startActivity(intent);
and have proper entry on your manifest for your MyApps class like:
<application>
.......
.....
<activity android:name="com.example.MyApps" />
........
</application>
Add
<activity android:name="com.example.MyApps"></activity>
in your manifest.

Categories

Resources