1

This is actually extended version of Alternatives to using an activity for each tab. The point is using views instead of activity is actually a good idea. If I have a button or some text then its fine. But what if I actually want an activity to be started on tab change, like a camera ? Is it still efficient to use views instead of activity ? If so, how do I do it ? Because calling new intent everytime is also heavy on memory I think.

Community
  • 1
  • 1
Prabhat
  • 2,261
  • 7
  • 46
  • 74
  • I saw this link and the AnalogClock is a view. What I want to know is if I use the camera's layout as view for a tab. When should I call the camera activity ? – Prabhat May 06 '11 at 04:00
  • http://stackoverflow.com/q/2970844/568613 Always Search Stack before asking..... And also see this blog post http://knol.google.com/k/tabs-and-tabhost – Anoop Chandrika HarisudhanNair May 06 '11 at 04:01

2 Answers2

0

But what if I actually want an activity to be started on tab change, like a camera ?

You cannot start an activity on a tab change. You cannot integrate a third-party activity (e.g., built in camera activity) in a tab.

Hence, if you want a camera preview in a tab, you have no choice but to do your own work with the Camera object and a SurfaceView.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • I have done this. I have created a SurfaceView. I just gave Camera as an example. What I want to know is when I click on, say, a tab named camera which actually should start my own camera activity, how do I do it with views being associated with tab? – Prabhat May 06 '11 at 11:53
  • @Prahabat: You cannot have the "tab named camera which actually should start my own camera activity". – CommonsWare May 06 '11 at 14:22
  • @CommonsWave: Currently I have implemented this. The logic is something like this. http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/CameraPreview.html I created an activity called CaptureActivity and associated it with the tab. When the tab is clicked the activity is launched. The CaptureActivity has surfaceCreated, surfaceChanged, surfaceDestroyed methods. Since it is told that having an activity for a tab is not efficient, I was wondering if I associate the camera layout with the tab instead, when should I call CaptureActivity. – Prabhat May 07 '11 at 00:12
0

If you want an activity launched with a tab change, then use activities. Don't get hung up on efficiency unless you're certain you have problems.

Views are presumably more efficient because they don't launch an activity, but since you're launching an activity anyway, what do you gain? I use tabbed activities in my app and they're fine, even on my underpowered phone.

Remember...

"Premature optimisation is the root of all evil"

Martin Stone
  • 12,682
  • 2
  • 39
  • 53