How to start an activity that is defined in other Android projects? - java

I have defined some common Activities in a library project and want to reuse these activity in my working project.
I declared my library project as Android library, use the fully-qualified name of the Activities and declare them in the AndroidManifest.xml of the new project. However, I get 'Unable to find explicit activity class' error when launching the application.
Any other configurations shall I do in order to start the Activities?

Either your activity is not in your manifest, or there is some problem with your library project causing the activity class to not be included in the APK.

You need to use Implicit Intent and Intent Filters, check this blog entry and the android documentation for more information.
I have made a very simple sample (quick and dirty but working here): http://dl.dropbox.com/u/5289718/DummyIntent.zip

Related

How could Appnext SDK start its own activity for its ads even if it's not in AndroidManifest.xml?

I'm working with the AppNext ads SDK and I found inside the Interstitial ad a display function that calls startActivity (new Intent (this.context, InterstitialActivity.class)).
InterstitialActivity extends the AppnextActivity class, which in turn extends Activity.
My question is: How could they start its activity without registering the InterstitialActivity class at the Manifest?
Android SDK permits merging manifests from multiple sources, including any libraries you depend on for your project. This way, such Android libraries could register their components like Activity or Service without the app developer touching the main AndroidManifest.xml at all.

How to close old activity before opening next?

I am building an Android app and are using the Parse SDK for Android.
Currently I am subscribing to channels with this in my main activity:
PushService.subscribe(this, "User_1_channel", MainActivity.class")
This works fine except for one thing. It opens up MainActivity and it gets put upon the other MainActivity in the stack which is very bad. I really want to remove the old activity before the new launches. I know I can do it with this but I have no idea where to put it since the Parse SDK handles everything.
launch.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
People say an alternative is to use a Custom broadcastreceiver. Problem with that approach is I have no idea how to subscribe to a channel without specifying an activity as the third parameter.
If you define the activity as SingleTask in your configuration file, it will indicate only that one activity will be used the Task.
android:launchMode="singleTask"

implementing android library project without subclassing all activities

I have created an Android project and set it as a library project in order to support a free and paid version of the App. The library project is set as a "...base" project and actually the paid version simply calls the base app including its Main Activity.
I need to make some changes to limit the Free version and I can easily override layout resources, but I'd like to know the simplest way to extend/override some of the Activities. Ideally, what I'd like to do is only subclass Activities where changes which limit functionality are required, but I'm hitting a few problems. My activities redirect to other activities within the App navigation and I'm finding that the error below is being generated:
03-11 13:54:10.068: E/AndroidRuntime(21264): android.content.ActivityNotFoundException: Unable to find explicit activity class {package.free/package.base.MainActivity}; have you declared this activity in your AndroidManifest.xml?
Obviously, I can add these to the manifest or I can abstract the redirects, but the 2nd option means that I need to subclass anything that can trigger a redirect or anything which can be the target of a redirect. Is there a simpler way?
I managed to get this all working as I wanted. It does mean you need to be quite specific with projects which are using a library project in terms of which object you want to instantiate (and the activities or fragments that are declared in the manifest). I posted this question purely because there's not enough information out there on how to actually implement this stuff. If there's sufficient interest I'll try to pull together a tutorial/blog to show the steps that I took to get this all up and running.

Android Views appear different when accessed via a JAR in libs

I'm working on a reusable library for Android. The library will include an Activity that developers can use in their apps.
The plan is to distribute the library as a JAR. Consequently, I'm laying out views at runtime in my Activity onCreate(), as I can't use XML resources.
However, I'm noticing this weird behavior where there are subtle size differences between my Activity in two contexts:
I'm running my project, directly launching the Activity (Manifest LAUNCHER definition).
I zip my project classes into a JAR, and import that JAR into another Android project (testing what other developers will do). This wrapping project fires an intent for my Activity.
Why would this be?
What I see is that the imported lib version (2) looks smaller. It's some kind of scaling factor that's being applied to the direct launch case (1) that isn't being applied to the imported lib.
I have tried:
making sure all my dimensions are in DiPs
converting my DiPs values to scaled View dimensions using getWindowManager().getDefaultDisplay().getMetrics() and TypedValue.applyDimension()

Android do activities require a manifest file?

So I was wondering if adding multiple activities in my app, do each require a manifest xml file or whatever?
I tried switching activities without it and it crashed.
Then I added the other activity and it worked.
I ask because I hate the use of xml so I try to do everything programatically.
You need to learn to love XML :-) Yes, every activity needs to be declared in the manifest.
Actually android use xml everywhere, manifest, layout, menu, preference, string etc.So get used to it.

Categories