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.
Related
I just following a tutorial to start a basic intent, and I get an error. Doing exact the same as the tutorial, created an empty Activity and just passed as argument to the intent. What is the problem?
Using a video tutorial: Lynda.com - Developing Android Apps Essential Training (2015)
The error you've got in IDE usually happens when you try to use Activity Context (keyword this) inside some callback, listener or anonymous function. In such situation this does not refer to the Context of the Activity.
That's why solution provided by #Vishal Patoliya should fix your problem because you're explicitly referring to the Context of the concrete Activity as follows:
Intent intent = new Intent(YourActivity.this,ItemUserSettingRattingActivity.class);
Try this
Intent intent = new Intent(YourActivity.this,ItemUserSettingRattingActivity.class);
startActivity(intent);
In case of Activtiy, you are going to another activity:--
Intent intent = new
Intent(YourActivity.this,ItemUserSettingRattingActivity.class);
startActivity(intent);
If you are passing intent from a fragment to open a activity then
Intent intent = new Intent(getActivity(),ItemUserSettingRattingActivity.class);
startActivity(intent);
Have you already created a class named ItemUserSettingRattingActivity.java? maybe you get an error it's because the intent you created didn't detect the class.
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.
When I have e.g. a custom service and a custom activity in the same ADT project, then I can use this in the service, to start my activity:
Intent i = new Intent(context, MyCustomActivity.class);
startActivity(i);
However when I have the service and activity in separate projects, then I cannot do this since I do not have a direct reference to MyCustomActivity.class. This is problematic: I do not wish to include a JAR just to be able to fix that broken reference, since I assume this will increase the package size and create redundant data on the device (i.e. activity code is duplicated between the service and activity packages). So instead, I use this (perhaps there are other options?):
Intent i = new Intent("com.mypackage.myStringActionName");
startActivity(i); //is this a broadcast?
OR
Intent i = new Intent("com.mypackage.myStringActionName");
sendBroadcast(i);
...But I don't really like sending broadcasts when all I want is to direct the intent to a single activity to tell it to start.
So, what other ways are there to go about avoiding duplication (in ADT)? Or else a better way to send direct intents?
you can try this:
Intent i = new Intent();
i.setComponent(new ComponentName(packageName, classname));
startActivity(i);
the className must contains the packageName and main activity name
Not sure how to explain this,hope you understand me.. Here is the problem :
I have a few packages in my app and I'm doing this :
Intent intent = new Intent(view.getContext(), com.example.app.Lol.class);
startActivity(intent);
and his code is in class which is in package : com.example.anotherone
It's not possible as I saw, that's why I'm asking..what I have to do, so I can be able to create an Intent like the example above.
Thanks anyway!
Make sure you are importing the class you want
import com.example.anotherone.Classname;
and pass Classname.class in your intent,
Intent intent = new Intent(view.getContext(), Classname.class);
And that your Manifest is updated with the correct name for the activity (com.example.anotherone.Classname).
If you want to start an activity from another application, you can do it by specifying the intent action. When you define the activity you want to start in its application Manifest file, you can set it's <action/> tag inside <intent-filter/> to whatever action you want. Then to start this activity from another application call
Intent intent = new Intent("your-action-name");
startActivity(intent);
Your application will be the only to answer on this action request and it will open. Hope this helps.
1.At first import the class you want.
2.pass the class name with intent.
For example:
import package.otherclassname.yourclassname;
Intent intent=new Intent(view.getContext(),yourclassname.class);