I want to use BaseGameActivity from the games examples:
https://github.com/playgameservices/android-samples/blob/master/BaseGameUtils/src/com/google/example/games/basegameutils/BaseGameActivity.java
but my game activity has to extend from another framework's activity class. Is there an implementation of BaseGameActivity factored out into a separate class so I don't have to have my activity inherit from it?
Thanks
BaseGameActivity is a pretty simple wrapper around GameHelper, which is the object that really does all the work. If you can't derive from BaseGameActivity, simply use GameHelper directly. The implementation of the BaseGameActivity class can serve as an example of how to hook up the GameHelper methods to your Activity's lifecycle.
In summary:
in your Activity's onCreate, create the GameHelper object.
from your Activity's onStart, call GameHelper's onStart
from your Activity's onStop, call GameHelper's onStop.
from your Activity's onActivityResult, call GameHelper's onActivityResult.
implement the GameHelperListener interface methods
There's no requirement to use exactly that BaseGameActivity. Create your own BaseGameActivity based on that source code but instead of
public abstract class BaseGameActivity extends FragmentActivity implements
GameHelper.GameHelperListener
put
public abstract class BaseGameActivity extends YourFrameworksActivity implements
GameHelper.GameHelperListener
Related
Is there any case such that: both class A and class B can extend AsyncTask at the same ? Or else, should it be one class C that extends AsyncTask?
Any number of classes can extend AsyncTask at the same time (or any other class). Extending means that the new class inherits fields and methods of super-class and can override super-class methods. The same applies to AsyncTask as well.
I have created an Activity which allows a user to create a page. This PageActivity extends an Activity. Can I create a class called Update PageActivity that extends PageActivity?
Yes, you can, as long as you did not declare PageActivity a final you may extend it.
Of course you can.
Activity is just like any other Java Class.
Make sure you override the relevant Activity lifecycle functions - onCreate, onResume, etc...
I am making an app in which i have to run an activity in background until the app is running.each activity related to this app is using first activity.how can it possible?
can i use the inheritance for this?
can anyone tell me any example of multilevel interitance in android?
You can create a BaseActivity class that extends Activity and all other Activities will extend this BaseActivity. Then what ever happened in all other activities (like resume and pause) will also effect the actions of BaseActivity.
If you have to accomplish background task you better to see android service
You are already extending the Activity class in a base class, and again you are extending this base class in other class. This is itself an example of multilevel inheritance. I am posting an example that may be relevant for your question:
public class basecls extends Activity{
/*The base class*/
}
public class secondcls extends basecls{
/* basecls extended by secondcls */
}
You can extend the secondcls in another class, and the new class will inherit all super classes such that you can use the methods of its super classes.
Your main activity is already using inheritance, since it extends the Activity class.
I have two different class(class A and Class B). i want to use the method of Class A in Class B. i normally used object for class A and called method in class B. but unfortunately i am getting Force close error. Is that any thing different to call a method of another class in android. I referred many articles in stackoverflow. but i cant understand properly. pls help me to find out the solution.
You should not create object like this, you should use context to call object like as below
((Class A) contextObject).function();
it runs perfectly on my system,
earlier class A and class B both are extending Activity and now only A extends Activity and B extends A and now B can call functions of A
this works for me:-
public class A extends Activity
{
functionOfA(){}
}
public class B extends A
{
//calling function of class A
functionOfA();
}
In case of Android, class which extends Activity will maintain its life cycle methods. if method which is defined in different class other current running activity may be killed or in pause state. so it is suggested that if method which is reusable in application should in different class for example (AppManager singleton class) rather than being in single activity class
u have to create constructor of class A
& in class B make an obj to class A
initialize it with
ClassA obj=new classA();
obj.method_A();
hope this will help
As I said in my comment, you shouldnt instantiate activities.
If your method uses some method that are called from a Context object, you can create a new class ( Class NewClass) that accepts a context parameter and implements your methods in it.
So this way, you can call your class from any activity:
NewClass nc = new NewClass(this);
Look up for some example of how to use a database in Android. It uses the same way.
Why is it that you need to call the super class in the android lifecycle? For example, in onCreate you need to call super.onCreate, or onDestroy super.onDestroy.
It makes sure that any relevant lifecycle management code across the full class hierarchy gets invoked.
If you have MyBaseActivity that extends Activity, and MySpecificActivity that extends MyBaseActivity, calling through to the lifecycle methods in the superclass at each level means MyBaseActivity will still be able to respond to lifecycle events.