How to send objects through bundle

前端 未结 11 1226
我寻月下人不归
我寻月下人不归 2020-11-27 13:15

I need to pass a reference to the class that does the majority of my processing through a bundle.

The problem is it has nothing to do with intents or contexts and ha

11条回答
  •  [愿得一人]
    2020-11-27 13:26

    You could use the global application state.

    Update:

    Customize and then add this to your AndroidManifest.xml :

    And then have a class in your project like this :

    package com.example;
    
    import android.app.Application;
    
    public class CustomApplication extends Application {
        public int someVariable = -1;
    }
    

    And because "It can be accessed via getApplication() from any Activity or Service", you use it like this:

    CustomApplication application = (CustomApplication)getApplication();
    application.someVariable = 123; 
    

    Hope that helps.

提交回复
热议问题