Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exchange data (objects) between different Android Activities?

Tags:

android

What is proper way to exchange data or objects between different Android Activities?

Welcome screen <-> Main Screen <-> Startup routines <-> Processing data <-> Settings

Is it normal/recommended to have more than one activity in Android app? in my opinion, it's somehow strange to have this model of data exchange inside application

like image 736
Ante Avatar asked Jul 29 '10 22:07

Ante


People also ask

How can I transfer data from one activity to another in Android?

We can send the data using the putExtra() method from one activity and get the data from the second activity using the getStringExtra() method.

How can we transfer data from one activity to third activity?

You can pass the value in 2 ways: Either you make a global Class and set the value in that class and access that class in your 3rd activity. You can use Intent to send your values from 1st activity to 2nd activity.

How can we redirect from one activity to another?

You need to use Intent Class in order to redirect from one activity class to another activity class. onOptionsItemSelected() Method will be trigged when you click the 'show setting' menu in the action bar.


1 Answers

Is it normal/recommended to have more than one activity in Android app?

Normal? Yes. Recommended? That depends on the app.

in my opinion, it's somehow strange to have this model of data exchange inside application

What do you do with Web apps? Well, you keep your model in a central spot (server) and you pass small bits of context data (URL parameters) in links between major units of UI (pages).

What do you do with desktop apps? Well, you keep your model in a central spot (database) and you pass small bits of context data (e.g., constructor parameters) in links between major units of UI (windows).

What do you do with Android apps? Well, you keep your model in a central spot (database, ContentProvider, etc.) and you pass small bits of context data (Intent extras) in links between major units of UI (activities).

like image 153
CommonsWare Avatar answered Sep 21 '22 13:09

CommonsWare