3

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.

G_comp
  • 162
  • 3
  • 12
  • How about grabbing a good book about UML first before asking such really very basic question? – qwerty_so Aug 12 '15 at 21:23
  • 2
    How about help me since you wrote a comment? – G_comp Aug 12 '15 at 21:33
  • Well, now your questions sound more profound and I took back the down vote. Btw: I guess you mean `Activity` _element_ rather than _class_. – qwerty_so Aug 13 '15 at 09:36
  • @ThomasKilian In this context, [Activity](http://developer.android.com/reference/android/app/Activity.html) is a class, isn't it? – sergej Aug 13 '15 at 13:48
  • @sergej Hmm. Activity diagram also have interruptible regions. So I would think that the mentioned activities are UML Activities. And one implements those Activities using Classes. Probably the OP should clarify this. – qwerty_so Aug 13 '15 at 14:39
  • @ThomasKilian Oh, I was thinking about the android class "Activity", not about the UML activity diagrams. – sergej Aug 13 '15 at 14:43
  • @sergej Looks like your guess was better than mine ;-) – qwerty_so Aug 13 '15 at 19:55

1 Answers1

8

Maybe something like this?

enter image description here

  • 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:

enter image description here

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.

enter image description here

sergej
  • 17,147
  • 6
  • 52
  • 89
  • thanks! I also have an Activity that has a NavigationDrawer, so I change the Fragments. Can I represent that in this diagram ? – G_comp Aug 13 '15 at 13:35
  • @G_comp Sure, it would be an aggregation: `AnActivity<>->NavigationDrawer` – sergej Aug 13 '15 at 13:46
  • but what about the Fragments? I need to represent them ? – G_comp Aug 13 '15 at 13:59
  • @G_comp I am not familiar with the NavigationDrawer Fragments stuff. Can you show it as source code? – sergej Aug 13 '15 at 14:16
  • this link will help http://manishkpr.webheavens.com/android-navigation-drawer-example-using-fragments/ . Basically, when the user clicks on an item from the navigation drawer the fragment is replaced, changing what is displayed on the screen – G_comp Aug 13 '15 at 14:39
  • can I represent the relashionship between the activity that has a Navigation Drawer and a Fragment the same way as an intent, only writing "replace" instead of "intent" ? Not sure if I made it clear – G_comp Aug 13 '15 at 15:08
  • @G_comp I can't see a Navigation Drawer in the code. Do you mean `DrawerLayout`? – sergej Aug 13 '15 at 15:14
  • this code is better: http://stackoverflow.com/questions/20638967/how-to-change-fragments-using-android-navigation-drawer – G_comp Aug 13 '15 at 16:11
  • @G_comp There is an aggregation relationship between the Activity class and NavigationDrawerFragment class. See [here](http://yuml.me/d71175b9). – sergej Aug 13 '15 at 19:53