0

I'm working on code that will be stuck inside other people's apps. I have two activities that both play off of a video view (with slightly different behavior). However, i'd definitely like to NOT rely on other people manually having to declare AndroidManifest.xml activities that i create. (some developers might just forget to declare it in their manifest)

So essentially, i'd like to be able to tell android to load an activity which is not declared in Manifest. How do i do this?

here are my thoughts:

1) I've tried subclassing a declared activity (declared activity referring to it being declared in AndroidManifest). however, calling this subclass throws a ActivityNotFoundException not surprisingly.

2) i COULD pass in a static view via a static method like:

public class Blah extends Activity {
    private static VideoView badIdea;
    public void setBadIdeaView(VideoView vv) { badIdea = vv; }
//... start it up as usual, but `badIdea` is now configured
}

but i really don't want to do this because a view holds on to a context, and i DO NOT want a static strong reference to an Activity context.

3) does anyone know how Android actually loads your activities? i'm guessing Android uses reflection to open an instance of the class.... but... i mean, why do activities have to be declared in a Manifest? is this for security purposes in order to prevent bad dynamic classloading? is this a possible solution?

thanks

David T.
  • 22,301
  • 23
  • 71
  • 123

1 Answers1

0

How do i do this?

You don't. All activities must be declared in the manifest.

However, i'd definitely like to NOT rely on other people manually having to declare AndroidManifest.xml activities that i create.

As suggested in a comment, if your code is implemented as an Android library project, you can try relying upon manifest merging.

some developers might just forget to declare it in their manifest

So? They should catch it in testing. You can also add sanity-checking to your exposed API, where you see if the app has your activities registered, by means of PackageManager, so that way your code will "fail fast" if they did not follow your instructions.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • :'( My code is an Android Project, but manifest merging wasn't available until ADT 20 (which is pretty new). So until the majority of devs start using it, it's not too much of an option right now. Oh, the other thing is that this particular activity is an "optional" feature (though i'd like them to use it) of the lib project, so devs may not actually catch that they forgot to declare it. – David T. Nov 11 '13 at 19:33
  • similarly, most of the developers integrating this android lib project has already had to make manifest changes to declare the main activities that my lib project uses. However, it sucks to tell devs to keep adding new manifest declarations (not everyone reading a wiki will always be detail oriented enough to do so) – David T. Nov 11 '13 at 19:34
  • @DavidT.: "ADT 20 (which is pretty new)" -- if 18 months is "pretty new", you have bigger problems. – CommonsWare Nov 11 '13 at 19:40
  • oops. sorry, i haven't kept up with ADT numbers (using Android Studio). so is it safe to assume 99% of devs have updated to ADT 20? – David T. Nov 11 '13 at 19:59
  • 2
    @DavidT.: I'd phrase it more as they have no excuse for being on an older version. I can think of no good reason why they would stick on ADT 19 or below, and so *if* they fail to put your activities in the manifest themselves and *if* they are running such an old set of tools that they do not get the manifest merging, it's seriously their own damn fault. I'd still document the stuff they need to have in their manifest, for those that need that information. – CommonsWare Nov 11 '13 at 20:02