I have been trying to invoke another activity from the mainactivity class with the code:
startActivity(new Intent("intent filter name here"));
However when I debug the application when it gets to this line I get a source not found message in the class file editor that says the source attachment does not contain the source for the file ClassLoader.class. There is an option to change the attached source "android.jar" but there is only one such file under the_targetAPI folder. How can i fix this?
Try this:
Intent intent = new Intent(this, secondactivity.class);
startActivity(intent);
And don't forget to add it to manifest.xml.
By upper error also try to clean or rebuild the project.
Intent from one activity to another:
Intent ii=new Intent(Firstactivity.this,Secondactivity.class);
startActivity(ii);
Import tis one :
import android.content.Intent;
Add both classes in your Manifest.xml:
<activity
android:name="com.example.task.secondActivity"
android:label="#string/app_name" />
Try this one , its may work. check the manfest.xml ,
Source not found ClassLoader.class when invoking an activity from main
this may be the reason. check it out :)
Happy coding :)
Related
I got log cat message from startAnotherActivity() method
private void startAnotherActivity() {
Log.i(TAG, "Entered startAnotherActivity()");
Intent intent = new Intent();
intent.setAction(ANOTHER_ACTIVITY);
intent.addCategory("android.intent.category.DEFAULT");
startActivity(intent);
}
Another activity doesn't start, no other messages in log cat.
How can I resolve this issue?
UPDATE#1:
Sorry, I forgot to mention that AnotherActivity is an Activity in the other application, and therefore ANOTHER_ACTIVITY == 'some.other.app.domain.ANOTHER_ACTIVITY'
Shouldn't Dalvik complain if it cannot find specified activity?
One possible reason may be not declaring other activity in the manifest. You can do this like the following:
<activity android:name="your.package.your.activity">
</activity>
And then you can start the activity by doing the following:
Intent intent = new Intent(CurrentActivity.this, NewActivity.class);
startActivity(intent);
Hope this helps.
Since it's an activity in another application, you may need to set the component (fully qualified package name and fully qualified activity name).
See here: How to start activity in another application?
Or here:
Launch an application from another application on Android
Finally I found out my mistake.
In the project there are two similar messages in two activities, so I thought that runs one, but that was another.
Thank you for your assistance!
Please help me how to call activity from a jar file in android:
My steps:
I had a AndroidLibrary project with a MainActivity.java
I had a AndroidApp project with a SplashActivity.java.
I imported AndroidLibrary.jar to libs folder of AndroidApp project and add build path
I added path MainActivity.java in AndroidManifest.xml file of AndroidApp project
In class SplashActivity.java i used code like this to call MainActivity.java from AndroidLibrary.jar
Intent intent = new Intent(SplashActivity.this, MainActivity.class);
startActivity(intent);
However, when I call an activity from jar file , it immediately fails with ClassNotFound exception.
To call just an Activity from an external .jar, you need to:
Create an Intent
Call a setClassName with two String parameters: The package containing your class, and the entire path of the class that you need to call
Start the activity.
For example:
final Intent it = new Intent();
it.setClassName("com.example.test", "com.example.test.NameOfYourActivity");
startActivity(it);
If you want to know how to convert Java bytecode to Dalvik bytecode, visit my blog
Thanks.
Alernate piece of code that works
final Intent it = new Intent(android.content.Intent.ACTION_VIEW);
it.setClassName(getApplicationContext(), "<complete path of the Activity class>");
startActivity(it);
Android Calling Library activity in another new project
Intent callIntent = new Intent(MainActivity.this, com.example.testinglib.Testing.class);
startActivityForResult(callIntent, 0);
Note: startActivity(intent); is not working.
follow steps,
Create an Intent.
Call a setClassName with two String parameters: The package
containing your class, and the entire path of the class that you
need to call.
Start the activity.
That's it.
I want to call a class of another project. I added it in the build path and also declared that class in the manifest file but when I call it gives me a no class found error. I am calling it from intent.
Intent intent = new Intent(getApplicationContext(), org.coolreader.CoolReader.class);
intent.putExtra("path", adapter.getItem(position).getPath());
startActivity(intent);
If you want to launch CoolReader from your program than look at this answer:
Intent coolReaderIntent = getPackageManager().getLaunchIntentForPackage("org.coolreader.CoolReader");
coolReaderIntent.putExtra("path", adapter.getItem(position).getPath());
startActivity(coolReaderIntent);
Of course, CoolReader (program) should be installed on the device.
In my app, I have to use Intent.setClassName or setComponent to start an activity in another package. There is no problem when I use Intent.setClass like
Intent intent = new Intent(getApplicationContext(), org.iustb.knowledebase.animation.transparent.MainTransparentActivity.class);
The suggestions to solve this problem on the web is that adding or android:exported="true" to the target activity in the AndroidManifest, but it doesn't work.
Is there anybody can help me?
i wrote the below code:
Intent intent = new Intent();
intent.setClassName(cursor.getString(pIndex), cursor.getString(cIndex));
startActivity(intent);
manifest file settings of the target activity:
<activity android:name="org.iustb.knowledebase.animation.transparent.MainTransparentActivity"
android:exported="true"></activity>
Did you make sure the values that the cursor returns the are correct ones?
The first parameter of the setClassName() should be the application package name, not the package where the Activity beings started is.
Assume the application package is: com.testandroid, but you want to start the other activity from the com.testandroid.other package, then your code should look like this:
intent.setClassName("com.testandroid", "com.testandroid.other.OtherActivity");
in my case it was a conflict between package=com.example.myApplication in the AndroidManifest.xml file under the <manifest> tag and applicationId in the build.gradle:app module under the defaultConfig tag. hope it would help.
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.