How to communicate between Android tabs

前端 未结 1 1357
礼貌的吻别
礼貌的吻别 2021-01-03 11:28

Im trying to setup some tabs for my android application, but i got stuck.

I cant find a way to communicate between the tabs..

I got 2 tabs.


|S

相关标签:
1条回答
  • 2021-01-03 12:13

    You definitely want to reconsider using Activities as the content of your tabs. The more standard approach is to use one Activity that uses Tabs to only show part of the layout when a particular tab is selected.

    The Android documentation has an excellent worked example, check out Hello, TabWidget.

    Alternative

    If for some reason you do need to use Activities, you can pass information between them by either adding values to the extras bundle within the Intent your using to open each Activity, or by extending the Application class.

    By extending the Application class (and implementing it as a Singleton) you get an object that will exist whenever any of your application components exist, providing a centralized place to store and transfer complex object data between application components.

    0 讨论(0)
提交回复
热议问题