If you were writing a play, you would, for the most part, be writing dialogue. Dialogue tends to be sequential; that is, one person speaks, then another, then another, etc. Sometimes one character might speak at length; other times, the dialogue may be rather rapid-fire and choppy, with characters interrupting one another, and perhaps even speaking at the same time. And sometimes, characters are silent, but engaged in some activity that the audience can see, as indicated in stage directions.
Composing has analogies to all these things. You can feature one particular instrument for a while, then focus on a different one, and continue soloing instruments sequentially, but you can also have instruments interrupting one another in a way similar to the rapid-fire, choppy dialogue described above. You can even have players wander about the stage while playing their instruments, or not playing their instruments, assuming their instruments are portable.
However, a significant difference between play-writing and composing music is that music typically has multiple instruments 'speaking' at the same time, whereas it would be unusual to have multiple characters in a play speak simultaneously, presumably because it would make it hard to understand what they were saying.
What is it about music that makes multiple instruments playing simultaneously work so well as to be the norm?
The answer is easy: The composer/arranger assigns different roles to different instruments (or different groups of instruments), and those roles can change occasionally.
A trumpet solo might be accompanied by slow-moving chords in the strings in a work for orchestra. In this case, the trumpet has a foreground role, while the strings are playing more of background (but essential, nonetheless!) role. Or the trumpet could be in 'dialogue' with another instrument, perhaps the oboe, where they take turns 'saying something,' and perhaps they might even overlap sometimes, while the strings continue in their background role. In that case, both the trumpet and oboe have a similar role.
A division of musical roles that you learn about in orchestration class is:
Foreground — Middle ground — Background.
In this case, the orchestrator/composer decides on a role for each instrument or choir of instruments, and writes accordingly. This 3-part division of roles is a bit more challenging to manage when you are only writing for two instruments, but it is nevertheless achievable if one of the instruments is piano, because you could, for example, have a LH bass line supporting a trumpet melody, while the RH plays chords. In this case, the trumpet would be foreground, piano LH middle ground, and piano RH (chords) would be background.
One interesting thing about music, though, is that you don't usually see more than three roles represented simultaneously, presumably because, like having several people speak at once in a play, it would result in information overload. However, there may be times where information overload is exactly what you want — perhaps to convey a sense of chaos in the music — in which case you should feel free to give it a try!
In any event, as you compose, decide on the role of each instrument at any given time, and consider altering that role periodically, perhaps with unexpected interruptions, or by having the instruments take turns being in the foreground/background, or with the instruments having identical roles sometimes (perhaps one is rhythmically doubling the other), etc.
Another parallel is that just as you wouldn't try to write a dialogue between two characters in a play by writing lines for one character first, and then, once that was finished, writing the lines for another, you would typically write for your two instruments at the same time too. Not to say that you CAN'T do it the other way — anything is worth a try if you wish to do so — but composers typically write for multiple instruments at the same time, probably because it seems the best way to allow the instruments to be equal partners in the music.