Best Practice: Transferring Objects Between Android Actions

I was wondering what is the best way to pass objects between actions? My registered user is located in the content item and should be able to return to this item after the login process. Therefore, I need to pass the content identifier between these actions.

I see two main options:

  • Pass the content identifier in the intent as a URI (intent.putExtra ()) and pass them between actions
  • Save the content identifier to local storage and load it after logging in.

Are there any other options and best practices?

+7
android user-interface
source share
1 answer

I would suggest using SharedPreferences , which is similar to option 2. which allows you to get the content identifier (or a string or json object) after closing the application. you can also encrypt the content identifier before putting it in sharedPreferences

Besides intention (ram) and local storage (rom / sdcard, including the database), I do not see any other option (locally).

Case 1: you need to resume work after closing the application
you must use local storage

Case 2: you do not need to resume work after closing the application

option 1: 0. load the first activity 1. start login_activity (startActivityForResult()) (do not call finish() ) 2. after login is done (call finish()) 3. activity is resumed (if login fail -> redirect to other activity ) option 2: 1. create a public class with a data member to save the content-id/activity class (you may assign singleton design pattern) 
+2
source share

All Articles