Android Class Diagram UML - android

I'm trying to create a class diagram for an android project.
I want my classes represent the activities, services and interfaces that I will implement.
There are several questions about it on the web, but I couldn't find a definitive answer.
I know that there aren't specific rules for Android and UML, but I have some doubts.
How can I represent the relationship between an Activity and a AsyncTask ?
How can I indicate that an Activity has an intent to another Activity ?
Maybe if someone has an example, will really help.

Maybe something like this?
MyBackgroundTask IS A AsyncTask
MyActivity IS A Activity
MyActivity HAS ONE MyBackgroundTask
You can use a dependency to show that there is an relationship between the AnActivity class and the AnotherActivity class:
In this case, it means that the AnActivity class requires the AnotherActivity class for its specification or implementation. Also, use notes to make it clear.
Update:
Another example:
MainActivity IS A FragmentActivity
MainActivity HAS SOME fragments. The fragments are of type String.

Related

What is an AbstractActivity in android?

What is an Abstract Activity in android? This question was asked at one of the interview. I tried searching about this at androidxref unfortunately not able to found.
Can any one help to answer this , Thanks!!
There is no such term in Android system called AbstractActivity.
Abstract activity is any activity which has been marked as abstract.
And like any other abstract java class, it cannot be instantiated and hence it will fail if passed as intent to startActivity() method. Also Android Studio will not allow you to declare such activity in the manifest file.
These abstract activities are mostly used by some android libraries to declare abstract methods and provides any method implementations useful for its task like login mechanism.
One of the advantage of this approach over an interface is that it can make use of activity callback methods.
As in comments the purpose of AbstractActivity is same as abstract class in java, which cannot be used directly(direct instance creation is not possible).
Using abstract activity you can define a group functionality for app activity screens.
For example,
LoginScreen: Abstract activity holding some functions defined
UserLoginScreen: specific ui/function for common user
AdminLoginScreen: specific ui/function for admin user

Multiple fragment listeners in one activity

Hi I have this one Activity, and I need to send data from it to two different fragments. Is there a way to set this up?
public class MainActivity extends AppCompatActivity implements{ FragmentOne.OnEventListener, fragmentTwo.OnEventListener {
private static String TAG = MainActivity.class.getSimpleName();
So basically I am trying to use one interface and I have all the other methods set up in my two fragments and everything works as intended for fragmentOne. I am just trying to figure out how to make the same listener and interface work for the second interface as well. Is there a way to make it work?
Thanks in advance!
As you wrote, "the same listener and interface", so you don't need to hold two instances of the interface, but just make the mainActivity implements the same one. (if it's not the case post your interface and fragments code).
I assume you are semi-following the android fragment tutorial? Please share the rest of your code.
It should work as long as your activity is correctly implementing both interfaces. Java cannot extend multiple classes but can implement multiple interfaces. However your activity must provide implementation for both of the onEventListeners.

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.

Multiple activities within a class?

So what I want to do is this. I want to have a class that contains other classes which start activities, but I'm not sure if its possible, or even a good idea. An Example:
public class General{
public class Activity1 extends Activity{
//Start Activity
}
}
Is there a way to call such an activity?
So the solution I chose to go with was to use packages. After reading about it here http://developer.android.com/guide/topics/manifest/manifest-intro.html and here Android: Including multiple Java Packages to Manifest , it seems like a better method to do what I stated above.

Share Same code in Activity and ListActivity

My project consists of couple of activity and ListActivity items, there is some common piece of code(Navigation bar and some other codes) which needs to be done on both type of activity.
Is there a way I extend the activity and write my piece of code, and let ListActivity also inherent that code ?
right now I am copying the same piece of code in two classes , one is Activity extended and other is ListActivity extended
You could also have the common code in a class CSuperCommon, and have each of your Activities contain an inner class that inherits from CSuperCommon. Some initialization will need to be done such as setting the parent view, context, etc.
There is no real multi inheritance in java (and so in android) but it is possible to simulate it: http://www.javaworld.com/javaworld/jw-10-2005/jw-1024-multiple.html.
Here is another answer from stackoverflow: How do Java Interfaces simulate multiple inheritance?
Have both extend a Base Activity class (which will have your common code) and implement a list view in one of them. Implementing a list view is very easy!

Categories

Resources