Reputation: 41
i have two activities that i want to update with an incoming SMS message from a BroadcastReceiver. i have two layouts like this one:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<EditText
android:id="@+id/myEditText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
i do not know how to make a BroadcastReceiver so the two layouts would be updated with SMS. can you help please ?
Upvotes: 1
Views: 1474
Reputation: 9735
+1 only one activity is visible at the same time, however if you want more than one activity to consume this broadcast, here is my suggestion.
both activities must register to that broadcast event. surely the active one will consume and react.
at this point add one more step
store smt in SharedPreferences, e.g. isBroadcasted = true
then
both activities onResume method must check for this value and reset to false after reacting
hope I could explain it clear enough, if not plz shout here so that I can try to attach sample code.
Upvotes: 1
Reputation: 67286
Here is a complete explanation and a Demo example for How to Update the UI in an Android Activity Using Data from a Background Service
Upvotes: 1