Not finding library activities declarations in the manifest - android

I have some project as a library named LibProj. It has a lot of activities that I want to use in MainProj project but I'm getting Activity Not Found error.
I have done these steps.
one of them is shown below.
Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
intent.setComponent(new ComponentName("packagename//ex-com.hello",
"classname//ex-com.hello.ExampleActivity"));
startActivity(intent);
Second one is to add all activities' declarations in manifest of my MainProj project.
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.doocat.MainActivity"
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=".activity.main.IntroActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen" >
</activity>
<activity
android:name=".activity.main.LoginActivity"
android:screenOrientation="portrait"
android:label="#string/app_name" />
<activity
etc...
Both of these ways not working. What I'm doing wrong or what is the solution?

Register Your Library Activity in MainProject manifest file..
I have given action name in intent-filter
com.lib.Example to identify which Activity need to call.
<activity
android:name="YOUR_LIBRARY_ACTIVITY_PACKAGE. ExampleActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="com.lib.Example" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Now call this Activity from your MainProject
Intent intent = new Intent("com.lib.Example");
try {
startActivity(intent);
} catch (ActivityNotFoundException e) {
}
Hope This help you.

Related

Cannot Start an Activity - Android

My Android Studio is autocompleting my code and it's going wrong.
What I'm trying to do is:
Intent intent = new Intent(getActivity(), DetailActivity.class);
startActivity(intent);
But it aways becomes:
Intent intent = new Intent(getActivity(), com.example.android.sunshine.app.DetailActivity.class);
startActivity(intent);
And there's an error on the word "sunshine" that make it get red.
If I try to build I get this:
Error:(97, 87) error: cannot find symbol class app<br>
I already saw other codes and they all work fine with the first code. What should I do?
Here is my AndroidManifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="app.com.example.android.sunshine" >
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
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=".DetailActivity"
android:label="#string/title_activity_detail"
android:parentActivityName=".MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="app.com.example.android.sunshine.MainActivity" />
</activity>
</application>
The Activity name (DetailActivity) in this line, is also red:
android:name=".DetailActivity"
In your second activity <meta-data> you have
android:value="app.com.example.android.sunshine.MainActivity"
Should probably be
android:value="com.example.android.sunshine.app.MainActivity"
And if the red marking on the sunshine word bothers you, hover your cursor over it and see what the Studio complains about -- probably just suspecting you misspelled sun shine (which you obviously didn't)

Android Studio 0.8.0 - Unable to find explicit activity class

I've got a problem trying to do something in android studio and i'm not getting any progress.
When I try to call a the activity Menu from Main Activity Android studio give me this error message:
31490-31515/com.example.agr.companion E/AndroidRuntime﹕ FATAL EXCEPTION: Thread-48434
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.agr.companion/android.view.Menu}; have you declared this activity in your AndroidManifest.xml?
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1556)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1431)
at android.app.Activity.startActivityForResult(Activity.java:3390)
at android.app.Activity.startActivityForResult(Activity.java:3351)
at android.app.Activity.startActivity(Activity.java:3561)
at android.app.Activity.startActivity(Activity.java:3529)
at com.example.agr.companion.MyActivity$1.run(MyActivity.java:26)
This is my manifest:
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MyActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Menu"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation" >
</activity>
</application>
</manifest>
And this is how I try to start the new activity:
Intent intent = new Intent(getApplicationContext(), Menu.class);
finish();
startActivity(intent);
I'm very lost, I tried lots of things but I don't find anything helpful. I've made other projects in android studio that have the same code and it work. Recently I upgrade to android studio 0.8.0 and maybe something changes...
Thanks in advance for your help
Your problem is that you try to start the view.Menu class as an activity, probably due to a false import. Take a look at the exception. It states com.example.agr.companion/android.view.Menu.
If you don't use a menu view in your activity, I would remove the false import at the top and add the correct one (of your com.example.agr.companion.Menu activity).
Another option is to rename your Menu.java activity to MenuActivity.java in order to avoid confusion.
The third option is to use:
Intent intent = new Intent(getApplicationContext(), com.example.agr.companion.Menu.class);
Try
<activity
android:name="com.example.agr.companion.MyActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

INSTALL_PARSE_FAILED_MANIFEST_MALFORMED when adding another activity

I am trying to add a second activity to my android manifest file but am receiving a INSTALL_PARSE_FAILED_MANIFEST_MALFORMED error. I have isolated the offending code to this line:
<activity android:name="com.MyPackage.Main.FacebookLoginActivity"
android:label="Facebook"></activity>
When I type it in like this
<activity android:name=".FacebookLoginActivity"
android:label="Facebook"></activity>
it works fine but when I try to start the activity via
this.startActivity(new Intent(this, FacebookLoginActivity.class));
I get an error saying cannot locate "com.MyPackage.Main/com.MyPackage.Main.FacebookLoginActivity".
Is that activity wrong in some way?
Here a portion of my manifest file:
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:allowBackup="true">
<activity
android:name=".MainActivity"
android:configChanges="orientation"
android:label="#string/app_name"
android:theme="#style/Theme.NoBackground">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.MyPackage.Main.FacebookLoginActivity" android:label="Facebook"></activity>
<activity android:name="com.facebook.LoginActivity"
android:theme="#android:style/Theme.Translucent.NoTitleBar"
android:label="#string/app_name" />
<meta-data android:name="com.facebook.sdk.ApplicationId"
android:value="#string/facebook_app_id"/>
</application>
Try changing you package declaration to com.mypackage.main.
Your class name would be com.mypackage.main.FacebookLoginActivity

searching unknown activity (java.lang.ClassNotFoundException)

help me to resolve this getting this exception
java.lang.RuntimeException: Unable to instantiate application delhi.roshanara.margapp.MargApp: java.lang.ClassNotFoundException: delhi.roshanara.margapp.MargApp in loader dalvik.system.PathClassLoader[/data/app/delhi.roshanara.margapp-2.apk]
It is searching MargApp Activity to open the project but there is no activity of this name. And I want to start my activity as .LoginActivity. Manifest file structure is given below:-
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
android:name="MargApp" >
<activity
android:name=".LoginActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".OrderMenuPage" />
<activity
android:name=".PartyOutstanding" />
<activity
android:name=".PartyPDC" />
<activity
android:name=".TakeOrder"></activity>
<activity
android:name=".ShowOutstanding"
android:screenOrientation="landscape" />
<activity
android:name=".ShowPDC"
android:screenOrientation="landscape"></activity>
</application>
I would try removing
android:name="MargApp"
if that didn't work try Cleaning up your project
Project>Clean
Do not use the android:name attribute! It, misleadingly, does not have anything to do with the name of your app and is actually the name of an extra class to load before loading your application. That's why you are getting the ClassNotFoundException. Remove it and it should work:
Replace your application tag with this one...
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >

Android manifest.xml

I'm working on the Tabs example from Google Android Developers site (http://developer.android.com/resources/tutorials/views/hello-tabwidget.html) but I'm stuck in step 2.
At the very end of step 2 says "Duplicate this for each of the three activities, and add the corresponding tags to the Android Manifest file"
What exactly do I have to add to the AndroidManifest.xml?
Thanks
This is how your Manifest file should be:
<activity android:name=".ArtistsActivity"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar">
</activity>
<activity android:name=".SongsActivity"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar">
</activity>
<activity android:name=".AlbumsActivity"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar">
</activity>
</application>
This will work for sure!!
just add every activity AndroidManifest.xml
main activity use:
<activity android:name=".Tabs">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
another activity use:
<activity android:name=".Tab1">
<intent-filter>
<action android:name="android.intent.action.EDIT"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Basically you have register each activities in AndroidManifest.xml like this
<activity android:name=".YourActivityName"/>
You have to add the corresponding <activity> tags for each one of the three activities. The AndroidManifest.xml file describes the components of the application (amongst other things like permissions and API level support).
In this example you have to add three definitions:
<activity android:name=".ArtistsActivity"/>
<activity android:name=".AlbumsActivity"/>
<activity android:name=".SongsActivity"/>

Categories

Resources