There is a class in a library that is called from javascript (html5 app). It can't be an Activity extender.
The class has access to Activity and WebView objects.
Is it possible to get onResume, onPause and onDestroy activity events from this library class?
On API Level 14+, you can call registerActivityLifecycleCallbacks() on your Application instance to find out about all callbacks to all activities in your app.
Or, modify your Activity to call the class in the library on each of those callbacks.
Mouse right click Source --> Override/Implement Method you can find methods which you need it. But make sure add your library on your project
Related
I am working on some legacy code for an android app, and in some activities when they want to finish the activity they write
finish()
and in other places they write
activity.this.finish()
what is the difference?
actvity.this is transparent in an Activity class, because it references to itself, so you can call a class method both using and not using it as in Java
I am new to android development.
So I have a question about activities.
On Google developer, they say you have to make a class which is inheriting from the class Activity.
So far so good. Now I am thinking an Activity is a class, which leads to my major problem.
So when activity is a class how can it invoke all the live cycle methods.
In Java, I learnt there must be an object of a class to invoke methods and actions. So when activity is not an object but a class, how is this possible.
Kindest regards
Jan
When a user starts your app the android operating system will instantiate an object based on your class which must be a subclass of Activity.
The operating system will use that object and call the lifecycle hooks (e.g. onCreate, onResume, ...) which you implented in your activity subclass when one of the related lifecycle events happens.
Here it is clearly mentioned under CREATING AN ACTIVITY header, that system calls the callback methods, based on which event has occurred. Suppose user is interacting with your activity, then using the object created by the OS for that activity, all the callback methods will be executed. Please refer.
I am working on an Android library and I am having an issue.
The main application calls an initialises a library. One of the parameters is the calling activity. This activity is then used as the context when needed.
When a certain event is triggered within the main application calls a method, which then calls a new activity. At the moment, the library class uses the activity that was passed into the initalise method to create the new activity (note that the passed in activity in the initialise may not be the activity that triggered the library as it only initialised once.
The activity that is started in the library, sets a result and finishes the activity. However, the onactivity result in the library class is not called (I presume because its not an activity and the result would go back to the activity that was passed in to the initialise.
What I need to be able to do is have the library class file to get the returned result from the libraries activity.
Android AccountManager does something like this. A request to AccountManager will invoke an authenticator plugin which can have an activity to get the user's username/password, etc.
AccountManager just uses a special Future called AccountManagerFuture to return the results asynchronously, and I would recommend you use a Future implementation as well to return your results asynchronously. Then you don't need to worry about how to make the two activities connect through the library.
I'm working on an Android app which has an activity and a widget. This is currently implemented via two classes in two .java files - one for the activity (extending Activity), one for the widget (extending AppWidgetProvider). Nothing out of the ordinary here as far as I'm aware...
However, the widget class code could be a lot simpler if it was to make use of functions and asynctasks defined in the activity class. Duplicating these functions seems like bad design, so I'm wondering how I can structure the app to make them usable?
Can I extend both Activity and AppWidgetProvider somehow? Can I import one in the other?
Thanks!
either make the funcs static, or make a 3rd class to hold these funcs
Move the functions down into a service. Create a Service and you can use context.startService(Intent) from you WigetProvider or from the activity to access the functions.
I need to start android application not with Activity^ but with some controller class that will start some activity
Is it possible?
I'm not sure if I understand your question correctly, but an Android application is built up by four "components" as mentioned in the "Android Application Fundamentals", http://developer.android.com/guide/topics/fundamentals.html (no, you don't need all four of them make your application work).
The most common way of starting an application (and actually the only one I've been in touch with) is to define an Activity in your applications AndroidManifest.xml file as described on the link above. NOTE! that an Activity doesn't have to define a UI; you are not obligated to call the "setContentView()" function. Hence your "controller class" can extend Activity and be the very Activity you define as the start-up Activity in your manifest xml. You can then call "startActivity()" function with parameters to start any other Activity, whenever you see fit, from your controller class (this is also described in the link above).
Hope this helps.
Either create a GUI-less activity without calling setContentView() or use a BroadcastReceiver that accepts launcher intents (action=MAIN, cateogry=LAUNCHER). In Activity.onCreate or receivers callback method you can place logic which will invoke the actual activity of choice.