Hi,
I'm currntly struggling with an Android problem whose answer is maybe simple. (I'm new in Android developing)
I have a main activity that builds a TabHost with two Tabs (each represents another Activity):
public class Main extends TabActivity {
private TabHost mTabHost;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mTabHost = getTabHost();
mTabHost.addTab(mTabHost.newTabSpec("tab1").setIndicator("tab1").setContent(new Intent(this, Class.forName("android.myApp.Activities.tab1"))));
mTabHost.addTab(mTabHost.newTabSpec("tab2").setIndicator("tab1").setContent(new Intent(this, Class.forName("android.myApp.Activities.tab2"))));
}
public void showAlert() {...}
}
Now I want to receive SMS Messages with a Broadcast Listener. This is done this way:
public class SMSConnection extends BroadcastReceiver {
@Override public void onReceive(Context context, Intent intent) { ...
Toast.makeText(context, str, Toast.LENGTH_SHORT).show();
// HERE I WANT TO CALL THE showAlert() Method in Main.java
}
}
The SMS Receiver works fine and shows the Toast.
Now I want to call the showAlert() Method in my Main.java Activity which would cause that the alert is shown in front of my tab view.
But how can I do that ??
As far as I know I can't receive broadcast messages within an activity - so the only thing I could do is to start a new activity out of my BroadcastReceiver. But instead I want to change my Tab View or show the alert.
Are there any possibilities to access an existing Activity from a broadcast receiver class ? Any other suggestions ?
Thanks in advance