Reputation: 10361
I want to show a messageBox or notification when connection lost in Static Database class. But I can't use getApplicationContext() as the class is static and I tried to call other class called notification but I have an error. So How could I pass activity object to my new class ?
Upvotes: 0
Views: 4183
Reputation: 208042
How are you doing it's wrong. You should pass a context each time when you call your static methods.
However you can have a static Context property in that class, and you could put in your current context before calling for a method. But this is bad practice! Don't do it!
Upvotes: 2
Reputation: 1397
You can also pass the activity context in the constructor of your class. Code would help though.
Upvotes: 0
Reputation: 1007614
You cannot have a "static DB class" that works with the UI in the fashion you are seeking. For any call that may fail, have an Activity
(or possibly other Context
) be passed in as a parameter to the method.
Upvotes: 0