B
B
BitNeBolt2020-03-10 15:49:40
Android
BitNeBolt, 2020-03-10 15:49:40

What is the best way to pass parameters to an activity?

When creating a new activity, you must pass your arguments to it. A similar question is described here, and as a solution two ways:

  • Use the putExtra() method of the Intent object .
  • Write a separate static method in the activity class and run it manually, passing parameters to it.

Which method is more logical, which is faster, which is more popular?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrew Nodermann, 2020-03-10
@BitNeBolt

The first method using Intent is great, there is nothing to optimize here, the parameters are parsed in microseconds.
The second method uses the OOP paradigm, which in turn allows you to implicitly pass parameters, in my opinion this complicates the logic and debugging of the application.

D
Dmtm, 2020-03-11
@Dmtm

for example, static newInstance for fragments has long become the standard,
so the rules of good manners require the second method, it is more correct because it allows you to hide serialization details (including keys by which parameters are passed), as well as control the number of parameters

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question