I’m writing a library for mobile devices. This library notifies the users when certain things happen (login, actions, etc). The way it works in iOS is modeled after GameCenter. A window animates down from the top of the screen, notifying the user, and then animates off.
In iOS, I can easily get the current view in the UIWindow and add my view to it. I’m fairly new to Android, and I can’t figure out how this is possible. It seems like unless you have knowledge of the current Activity and its layout, you can’t add a view to it.
Is what I want to accomplish even possible? Is this even the correct solution for Android or would an Android user expect something different?
If these are your first applications in Android, use XML layours put in resourses. In this case you always must know what Activity are you in. Whithout it you can’t read resources.
If you use pure code for views, you alweys can get your activity, because every your activity is a class. Put all operations in the class base for all your activities and use
this.classin them for obtaining the current activity name.You can also pass the current activity as a parameter into the library functions. So you have access not only to its root view, but to the context, to, and that will allow you to show toast messages about problems and have access to resources. (Passing context is a very common practice in Android coding.)