2

From what I understand, and activity is equivalent to a "page" in a web app.

For example, the list view would be one activity, edit view another activity, and add view a third activity.

While this works as expected, android activities seem to operate as individual apps--the action bar is different for each activity and so are the menus.

Is my usage of activities above correct or should I be using some other mechanism such as swapping out layouts and views?

TheOne
  • 10,819
  • 20
  • 81
  • 119
  • 1
    You are wrong in assuming that ListView, EditView, etc. are separate activities. They are just separate UI elements, with multiple instances possible per one activity. But you can see one activity as one single application / one "page" of a multi-page application. An activity (as the name suggests) is a construct that allows the user to perform an ... activity. When you look at it from coding viewpoint, each activity is its own separate program from start to end with only loose programming bindings to other app activities. A fragment on the other hand is a more integral solution. – velis Mar 17 '14 at 14:18
  • @velis, you're assuming my assumption. :) – TheOne Mar 17 '14 at 14:47

4 Answers4

0

Fragments are a core part of activities - not that much different. The use of fragments comes since Honeycomb 3.0 and the idea is an option to split the screen in several fragments at once. For example if you look at the gmail app for a tablet - you have one fragment on the left dealing with navigation and then the next fragment on the right is the list of emails.

On a mobile device, viewing area is limited, so you it could be said that fragments sort of behave like an activity - you interact with one fragment, which triggers another and so on and so fort. But in the end you always reference a super activity of each of these fragments - for example when you want to access the context.

So if you just want to wrap web pages in WebViews, stick with activities. If your scenario might involve developing for both tablets and phones, then go for the fragments.

Alternatively, you can read about the design philosophies of both here: http://developer.android.com/guide/components/fragments.html

Good luck!

lapadets
  • 1,067
  • 10
  • 38
0

From what I know, Fragments would be a good option to be able use different configurations/real estates on different devices. For example, if you are on a device with big real estate like Tablets or TVs you can display more content in a single activity, on the other hand for a devices with smaller real estate you can show content based on a progressive manner.

See this: http://developer.android.com/training/multiscreen/adaptui.html

Note that Fragments are supported only on devices running Android 3.0, so you might have to use Support Fragments (See: https://stackoverflow.com/a/6528757/713778)

But Again it depends on your specific needs. I am not sure what your exact use case is, but I would suggest you to watch some Android design in Action for some examples to improve your design and make your app "User Centric" (See: https://www.youtube.com/playlist?list=PLWz5rJ2EKKc8j2B95zGMb8muZvrIy-wcF)

I recently came across this https://www.youtube.com/playlist?list=PLWz5rJ2EKKc-riD21lnOjVYBqSkNII3_k seems provide an in-depth analysis on User Experience.

Community
  • 1
  • 1
ranjk89
  • 1,380
  • 16
  • 21
0

Fragments are to be used when you have common feature across multiple activities. From my perspective you should use individual activities as there will be back-end code to support (fetch and validate data, i.e. business logic). This way you have more modular code. Fragments is a new feature from v3.0.

ankitjaininfo
  • 11,961
  • 7
  • 52
  • 75
0

I would recommend using fragment for web like views. Fragments are pretty snappy compared to activities and reusable.

But before you start, make sure to fragments are good fit for your requirements since they are supported from android 3.0.

You can declare fragments from xml itself or you can create frame layout and add that view in the code itself.

http://www.c-sharpcorner.com/UploadFile/2fd686/fragments/

The above link has a good example tabhost.

Oliver.Oakley
  • 628
  • 2
  • 7
  • 23