How to pass an object from one activity to another on Android

后端 未结 30 3957
遇见更好的自我
遇见更好的自我 2020-11-21 04:03

I am trying to work on sending an object of my customer class from one Activity and display it in another Activity.

The code for t

30条回答
  •  离开以前
    2020-11-21 04:52

    The best way is to have a class (call it Control) in your application that will hold a static variable of type 'Customer' (in your case). Initialize the variable in your Activity A.

    For example:

    Control.Customer = CustomerClass;
    

    Then go to Activity B and fetch it from Control class. Don't forget to assign a null after using the variable, otherwise memory will be wasted.

提交回复
热议问题