1

In this simple example I have two activities ActivityA and ActivityB.

ActivityA is the foreground activity. User clicks a button that executes dispatchActivityBIntent() that creates a intent and dispatches it to start ActivityB.

Intent intent = new Intent(this, ActivityB.class);
startActivity(intent);

These are the diagrams I came up with

enter image description here

enter image description here

I found a previous answer discuss about potraying this in a class diagram.

Android Class Diagram UML

enter image description here

Alternate way. Is this wrong to show like this?

enter image description here

Enzio
  • 799
  • 13
  • 32
  • 1
    Cross posted https://softwareengineering.stackexchange.com/questions/408984/android-how-to-represent-one-activity-starting-another-activity-with-an-intent – qwerty_so Apr 19 '20 at 10:27

2 Answers2

1

If I well understand and trying to reuse your wording the sequence diagram can be :

enter image description here

I supposed all messages are asynchronous except of course the creation of the instance intent.

The fact the top of intent is not at the top of the diagram indicates it is created and does not exist before. To show the message create is just a way to do, an other representation is to have a message going to the rectangle of the instance ... but I do not manages that in my tool ;-)

I also supposed the life of intent is limited, the X indicates when it disappears

I preferred to replace Actor (if I well understand you : the user) by a Button because of User clicks a button that executes....

bruno
  • 32,421
  • 7
  • 25
  • 37
  • hi, thanks for the answer. could you tell me how the intent would be shown in the class diagram? – Enzio Apr 18 '20 at 16:24
  • 1
    @Enzio probably as you did just with the dependency stereotyped *intent*, you can also show the class Intent but you cannot associate it more than with a dependency again, and at that level a dependency has no real meaning. Else you have to enter in more details like in the link you give. The *Intent* management is more about the dynamic point of view (collaboration => sequence diagram etc) rather than the static point of view (class diagram) – bruno Apr 18 '20 at 16:28
  • I don't understand what you meant by " just with the dependency stereotyped intent". – Enzio Apr 19 '20 at 02:39
  • "Else you have to enter in more details like in the link you give" The link gives a very simple class diagram that I added to my answer above. Can I do the class diagram like that and do the sequence diagram as you mentioned? In that case the Intent class given in sequence diagram is not its' own class in class diagram. If you get what I'm saying. – Enzio Apr 19 '20 at 02:41
  • Also, can you check the alternate diagram I added to the question? Can I show like that without declaring the intent? – Enzio Apr 19 '20 at 03:42
  • @Enzio your question is "How to represent one activity starting another activity with an intent", where is the intent in your seq diagram ? what means the message stereotyped 'create' ? it is like is activityb is created, but this is false – bruno Apr 19 '20 at 06:19
  • Okey I understand now that the final diagram is wrong, If I draw the sequence diagram as you did, how do I represent the Intent in class diagram. What you mentioned as " just with the dependency stereotyped intent". I didn't understand that part. – Enzio Apr 19 '20 at 06:25
  • @Enzio if you draw Intent in a class diagram that class will probably be without relation with the other classes, except if ActivityA memorizes it in *startActivity(intent);* but I do not know what *startActivity* does. About "just with the dependency stereotyped intent" this is what is done in https://i.stack.imgur.com/FRlm6.png – bruno Apr 19 '20 at 06:38
  • If ActivityA creates the intent, as described in the narrative, shouldn't the [create message](https://www.uml-diagrams.org/interaction-message.html#create) be used ? And in this case shouldn't a dashed line with an open arrow head. be used instead of the plain arrow for an ordinary synchronous message (p.575 of the UML spec + [here](https://softwareengineering.stackexchange.com/a/402017/209774)) ? – Christophe Apr 19 '20 at 14:10
  • @Christophe as I said in my answer my tool doesn't allow to have the message going to the instance. The OP code is "*Intent intent = new Intent(this, ActivityB.class);*" => the instance is created synchronously, so I used a synchronous message for *create*. – bruno Apr 19 '20 at 14:29
  • @bruno Ah! I missed this, sorry. However, going to the instance or not, the creation should not be represented with a synchronous message even if the creation is synchronous (see references in my previous comment): this practice - even if it’s common - is not compliant with the notation. – Christophe Apr 19 '20 at 15:00
  • @Christophe again, I don't have the notation for the *create message* in my tool, how can I use a notation not available ? – bruno Apr 19 '20 at 15:14
  • @bruno Sorry again! I understood from your previous explanations that the tool didn't have the possibility to go to the instance's rectangle (which btw seems not mandatory in the spec). I didn't get that the tool didn't support this `messageSort` at all. For the next release? ;-) – Christophe Apr 19 '20 at 15:32
0

In my opinion uml-diagrams exist to to give you an overview of some software and not to describe a technical implementation details (like dispatch/intent).

I would prefer something like a stat-diagramm where every state is a Dialog or Activiy. The Arrows between the states could be the flow between the pages, labled with the name of the button (or Intent that is used)

k3b
  • 14,517
  • 7
  • 53
  • 85