Can an activity have two implements? - android

Can I implement OnClickListener and SurfaceHolder like this :
public class MainActivity extends Activity implements SurfaceHolder.Callback,OnClickListener

Yes, in Java a class can implement many different interfaces.
This compensates the lack of multiple inheritance in Java, as opposed to e.g. C++ where multiple inheritance is allowed.

Related

How to extend two activities in same class?

I'm new to android programming how to extend two activity . In my case I'm using ActionBarActivity
im already extends the a class for some functionalities how shall i extend two activities my class
any example code will be more useful for me
This is not much of a Android problem (as Activity is class as any other), it's the way Java works.
Java doesn't support multiple inheritance, so classes can only extend one other class.
class A extends B{
}
Even in this case:
class A {
}
class A extends another class - Object - but it is automatically implied without having to specify it.
If you want to ensure some functionality from several sources you will have to use interfaces and the implements keyword:
class A extends B implements C,D,E {
}

Android: How to extends my Activity class with RoboActivity + ActionBarActivity

I would like to use RoboActivity with my activity, but I don't know how to do that coz my current activity extends already ActionBarActivity:
public class MainActivity extends ActionBarActivity
Thank you so much
For RoboGuice 3 simply extend from RoboActionBarActivity.
You can simply copy the relevant RoboActivity parts into your subclass of ActionBarActivity. From the official docs https://github.com/roboguice/roboguice/wiki/Using-your-own-BaseActivity-with-RoboGuice:
In case your base activity class already extends a different library, the best way to get all the power of RoboGuice is to copy all the code contained in RoboActivity.
An example is also provided therein.

How to use multilevel inheritance in android

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.

Android - abstract class that extends activity or TabActivity

I have created an abstract class which extends the Activity Class.
I want to extend it in an activity which extends TabActivity Class, how can I achieve that?
Get the TabActivity and abstract class Functionality at the same time.
I do realize that multiple inheritance is not possible in Java, but can I avoid extending TabActivity Class and still use getTabHost()?
10x :)
I don't think you can achieve this with this design. If your abstract class extending SomeOtherActivityClass and new Class need to extended SomeotherActivityClass (through inheritence) and TabActivityClass, that may confuse dalvik to choose which activity at runtime and it doesn't make sense. You may need to reconsider your design.
yes sure, you can use. By using following snippet:
TabHost host=(TabHost)findViewById(id of tabhost);
It's better way to create another class that extends Application class. Or use singleton pattern and create class with all functionality that you're need.

public abstract class Hand implements Comparable<Hand> , Serializable{

If Hand is self defined abstract class , then it implements itself as template? it doesn't make too sense. what's your take on the above declaration
From docs.oracle.com:
"It is possible, however, to define a class that does not implement all of the interface methods, provided that the class is declared to be abstract."
The declaration you have only names two interfaces: Comparable, and Serializable. Since Hand is an abstract class, it doesn't have to actually implement those interfaces, but any non-abstract class that extends Hand must do so.
The page: http://docs.oracle.com/javase/tutorial/java/IandI/abstract.html has more good info/explanation.
If class implements some generic interface, passing itself as parameter, it means the class implements some methods with itself as parameter. So in case of Comparable it tells, that class MUST have method compareTo to compare itself with another instance of the class.
Makes sense to me. It means that you can compare two hands.

Categories

Resources