[Solved] Using activity and TabHost

Common bugs/problems with the Android SDK the Emulator and the ADT-Plugin.

[Solved] Using activity and TabHost

Postby macuserlambda » Wed Apr 06, 2011 3:26 pm

Hi,

I've posted a question with an other in an other thread : http://www.anddev.org/sdk-adt-emulator-problems-f16/fail-to-connect-to-camera-service-t52046.html

So I think it's better to create a new thread for it. Here is the issue :

I have a tabbar. The first tab contains my camera preview activity. The second contains a ListView activity and the third contains a WebView activity.
When I show the second tab, onPause of the first activity and so stopPreview() are called as expected. But when, in my second tab, I create an Itent to show a new activity, onStop of first Activity is called !
And when I press back button to come back to the ListView, onResume is called in the first tab. Despite the fact that it's the second one which appears...

I'm new in Android dev so may be I don't understand the whole mechanism.

In iOS, I'm doing the same thing. I have an UITabBarController which contains three UIViewControllers. When I'm in the second tab, I call presentModalViewController to show a new UIViewController in fullscreen. When I dismiss this new UIViewController, viewWillAppear method is called only in the second tab as expected. The one of first or third tab is not called.

Moreover, onPause method of the first tab is called when I switch to second tab, which means I leave the first Activity and onResume should be called only when I switch back to the first tab.

I'm french, it's difficult for me to explain that in english so I hope I make myself clear... :)
Last edited by macuserlambda on Fri Apr 22, 2011 10:01 am, edited 1 time in total.
macuserlambda
Junior Developer
Junior Developer
 
Posts: 15
Joined: Mon Mar 28, 2011 10:43 am

Top

Re: Using activity and TabHost

Postby macuserlambda » Mon Apr 11, 2011 4:24 pm

Hi,

here is my source code that create listview and set the listener to create my new Activity. I hope it will make someone to help me :

Code: Select all
        ListView list = new ListView(this); 
        list.setAdapter(adapter);
        list.setOnItemClickListener(new OnItemClickListener() {
              public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
                 Intent intent = new Intent(getApplicationContext(), MyActivity.class);
                 Bundle bundle = new Bundle();
                  bundle.putSerializable("object", myObjects.get(position));
                  intent.putExtras(bundle);
                  
                  startActivity(intent);
              }
        });
       
        this.setContentView(list);
macuserlambda
Junior Developer
Junior Developer
 
Posts: 15
Joined: Mon Mar 28, 2011 10:43 am

Re: Using activity and TabHost

Postby macuserlambda » Thu Apr 21, 2011 2:35 pm

I can't fix this bug !

I've compiled on Android 1.6 and it works well...

did Google regress in new versions ?!

Nobody met the same issue ?
macuserlambda
Junior Developer
Junior Developer
 
Posts: 15
Joined: Mon Mar 28, 2011 10:43 am

Re: Using activity and TabHost

Postby iaindownie » Thu Apr 21, 2011 4:29 pm

What about just finishing the current acivity with:

Intent intent2 = new Intent();
setResult(RESULT_OK, intent2);
finish();
User avatar
iaindownie
Experienced Developer
Experienced Developer
 
Posts: 84
Joined: Mon Dec 29, 2008 4:08 pm
Location: Thetford, Norfolk, UK

Re: Using activity and TabHost

Postby macuserlambda » Fri Apr 22, 2011 9:41 am

Thanks for your answer.

I've tried :

Code: Select all
              public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3)
              {
                  Intent intent = new Intent(getApplicationContext(), MyActivity.class);
                  setResult(RESULT_OK, intent);
                  Bundle bundle = new Bundle();
                  bundle.putSerializable("object", myObjects.get(position));
                  intent.putExtras(bundle);
                 
                  startActivity(intent);
                  finish();
              }


But when I press the back button, I leave the app.

I would like to come back to the second tab (listview). It already does but it's very long, there is no swipe animation and the swipe animation is displayed when I click the first tab...

May be I have to finish my Activity and intercept when back button is pressed to reload the previous activity ? But how ?
macuserlambda
Junior Developer
Junior Developer
 
Posts: 15
Joined: Mon Mar 28, 2011 10:43 am

Re: Using activity and TabHost

Postby macuserlambda » Fri Apr 22, 2011 10:00 am

Solved !!!

I finish the current Activity as you telle me and I recreate the previous when back button is pressed :

Code: Select all
   public void onBackPressed() {
      Log.v(TAG, "back pressed");
      Intent intent = new Intent(this.getApplication(), MyTabActivity.class);
      setResult(RESULT_OK, intent);
      intent.putExtra("selectedTab", 1);
      finish();
      startActivity(intent);
      return;
   }


Thank you for your help !!
macuserlambda
Junior Developer
Junior Developer
 
Posts: 15
Joined: Mon Mar 28, 2011 10:43 am

Top

Return to SDK/ADT/Emulator Problems

Who is online

Users browsing this forum: No registered users and 6 guests