How to reference child activity from TabHost to call a public function?

My approach would be to define a nested 'listener' class in the child activity which extends BroadcastReceiver I would then simply broadcast an Intent from my TabActivity which would then trigger the BroadcastReceiver to perform the action EDIT: To give example code The steps are Define the intent filter in the manifest Add the nested 'listener' to the child activity Set onResume()/onPause() in child activity to register/unregister the listener Create intent in TabActivity and broadcast it when you want child to do something In AndroidManifest. Xml activity android:name=". MyActivity" android:label="@string/app_name" Java public class MyActivity extends Activity { private MyListener listener = null; private Boolean MyListenerIsRegistered = false; @Override public void onCreate(Bundle savedInstanceState) { super.

OnCreated(savedInstanceState); listener = new MyListener(); } @Override protected void onResume() { super.onResume(); if (!MyListenerIsRegistered) { registerReceiver(listener, new IntentFilter("com.mycompany.myApp. DO_SOMETHING")); MyListenerIsRegisterd = true; } } @Override protected void onPause() { super.onPause(); if (MyListenerIsRegistered) { unregisterReceiver(listener); MyListenerIsRegistered = false; } } // Nested 'listener' protected class MyListener extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { // No need to check for the action unless the listener will // will handle more than one - let's do it anyway if (intent.getAction(). Equals("com.mycompany.myApp.

DO_SOMETHING")) { // Do something } } } } In the main TabActivity private void MakeChildDoSomething() { Intent I = new Intent(); i. SetAction("com.mycompany.myApp. DO_SOMETHING"); sendBroadcast(i); }.

My approach would be to define a nested 'listener' class in the child activity which extends BroadcastReceiver. I would then simply broadcast an Intent from my TabActivity which would then trigger the BroadcastReceiver to perform the action. EDIT: To give example code... The steps are... Define the intent filter in the manifest Add the nested 'listener' to the child activity Set onResume()/onPause() in child activity to register/unregister the listener Create intent in TabActivity and broadcast it when you want child to do something In AndroidManifest.

Xml In MyActivity. Java public class MyActivity extends Activity { private MyListener listener = null; private Boolean MyListenerIsRegistered = false; @Override public void onCreate(Bundle savedInstanceState) { super. OnCreated(savedInstanceState); listener = new MyListener(); } @Override protected void onResume() { super.onResume(); if (!MyListenerIsRegistered) { registerReceiver(listener, new IntentFilter("com.mycompany.myApp.

DO_SOMETHING")); MyListenerIsRegisterd = true; } } @Override protected void onPause() { super.onPause(); if (MyListenerIsRegistered) { unregisterReceiver(listener); MyListenerIsRegistered = false; } } // Nested 'listener' protected class MyListener extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { // No need to check for the action unless the listener will // will handle more than one - let's do it anyway if (intent.getAction(). Equals("com.mycompany.myApp. DO_SOMETHING")) { // Do something } } } } In the main TabActivity private void MakeChildDoSomething() { Intent I = new Intent(); i.

SetAction("com.mycompany.myApp. DO_SOMETHING"); sendBroadcast(i); }.

Well I would like to avoid that if possible. I am able to access public function of the parent from the child activity without any problems, I should be able to do the same the other way, I hope – android-developer Mar 23 at 1:22 @android-developer: Your choice but it's trivial to do and works. It also means the 'parent' TabActivity doesn't need to know specific method names of its children - all it has to do is send an intent saying 'Do this' and the child activity then handles it internally.It's also the commonest way for activities to communicate with each other.

– MisterSquonk Mar 23 at 4:11 @MisterSquonk: would you provide me with some code on how to accomplish this or point me to the right direction? I would appreciate it. – android-developer Mar 23 at 4:46 @android-developer: See my EDIT - it looks more than it really is because I had to frame it properly for the example.

In reality there's less than 30 lines of extra code. – MisterSquonk Mar 23 at 5:55 @MisterSquonk - that works flawlessly, exactly what I needed - THANK YOU! – android-developer Mar 23 at 14:53.

Well, the trick is to store the TAG associated with each tab, and use it to call the respective activity. Lets say we want to invoke a method “refreshContent()� That is inside the Tab1 Activity.

And that’s it! Now for the opposite direction, we want to call some method “updateMain()� Inside MainActivity, from the child tab TabActivity1.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions