skip to Main Content

I have 5 activities :
*Activity 1 ( details of one game tournament (
*Activity 2 (details of another game tournament) and so on….
*Activity 5 ( payment activity)

In each activity there is some data with one button and I want to send that data to payment activity whenever user clicks any activity(1-4)

2

Answers


  1. Use Intent to send data between activities

    Intent intent = new Intent(context, Another.class);
    intent.putExtra(“message_key”, message);
    startActivity(intent);
    

    then use this code to get your data

    Intent intent = getIntent();
    String str = intent.getStringExtra(“message_key”);
    

    Happy coding

    Login or Signup to reply.
  2. or you can try SharedPreferences

    creat object class

    object Session {
    
        private val NAME = "SOME_NAME"
        private val MODE = Context.MODE_PRIVATE
        private lateinit var preferences: SharedPreferences
    
        fun init(context: Context) {
            preferences = context.getSharedPreferences(NAME, MODE)
        }
    
        private inline fun SharedPreferences.edit(operation: (SharedPreferences.Editor) -> Unit) {
            val editor = edit()
            operation(editor)
            editor.apply()
        }
    
        fun setString(tag: String, value: String) {
            preferences.edit {
                it.putString(tag, value)
            }
        }
    
        fun getString(tag: String) = preferences.getString(tag, "")
    }
    

    init that in Application inside onCreate

    class MyApp: Application(){
        override fun onCreate() {
            super.onCreate()
            Session.init(this)
        }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search