János
János

Reputation: 35050

startActivity should performed on main thread?

Need to do a transition from one activity to an other. Need startActivity(intent); executed on main thread on it can be a worker thread? I would choose main thread concept, because there are GUI related operations. What do you think?

Upvotes: 1

Views: 4510

Answers (3)

Bonatti
Bonatti

Reputation: 2781

Yes, it should, but as others stated is not required to do so.

Basically, "where", in the sense of Context, your new Activity should be placed in its stack or under/above others.

From documentation:

Launch a new activity. You will not receive any information about when the activity exits.

Note that if this method is being called from outside of an Activity Context, then the Intent must include the FLAG_ACTIVITY_NEW_TASK launch flag. This is because, without being started from an existing Activity, there is no existing task in which to place the new activity and thus it needs to be placed in its own separate task.

Upvotes: 2

Demonsoul
Demonsoul

Reputation: 801

Previous answers have revealed that the startActivity method itself ensures the relevant operations are run on the main thread, so it doesn't actually matter where you call it: Is it safe to launch and activity from a non-ui thread?

Upvotes: 2

Diadev
Diadev

Reputation: 11

If i'm not wrong... startActivity() internally executes in the UI thread so there's no discussion :)

Upvotes: 0

Related Questions