开发者

API Class across all Activities

I'm making an app in conjunction with a websites API, and in the application I created a class that would deal with the OAuth authentication and API calls. Now, how would I be able to instantiate an object from that class, and share the object across various Activities? I'm quite su开发者_StackOverflow社区re what would be the best practice in a situation like this.

Thanks a bunch!


You could create a subclass of Application and store your authorization module there. This would be accessible to all of your activities within that process.

You just need to declare you Application subclass in your manifest and it will be instantiated instead of the default.

From your Activity, you would call getApplication() and cast it to the correct subclass type and access your custom methods

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜