I have an Android application that works with sms messages. When new sms message arrives Android, will call code from my class that is "NEW_SMS" broadcast receiver. As you know, "onReceive" method in my "sms_recieved_class" gets some context (from the system). Using intents, my sms broadcast receiver calls another class that does something with sms database (context originally got from system via "onReceive" is used to invoke code from other class by sending another broadcast).
That other class works with sms database and it's also a broadcast receiver. It reacts on broadcasts sent by my class mentioned above. If "messing" with database goes wrong, app should show custom error dialog. Now, THERE's the problem!
Custom error dialog code:
public static void setUpError(Context act,String ERRMSG, StackTraceElement[] stack) {
AlertDialog.Builder builder = new AlertDialog.Builder(act);
final StackTraceElement[] finStack = stack;
final String errMsg=ERRMSG;
final Context ctxFin = act;
builder.setMessage(poruka)...setting up alert buttons...
AlertDialog alert = builder.create();
alert.show();
}
Error goes off at "alert.show()" line. I'm confused cause when i try to show this dialog while my app is visible (and pass "someAct.this" as Context) everything is fine. When i try to show alert using Context taken from "broadcastReceiver.onReceive" (called by the system) i got error. What i'm doing wrong?
P.S. after searching for answer on STOVF, every time the solution was "don't use getApplicationContext()". Since both of my classes that are called when phone gets new message AREN'T of type "Activity", what should i do?