-3

I'm a total newbie to Android programming and am trying to create a program which contains public transport schedules.

I've been trying to create many buttons(Cities, bus numbers etc.), with each button leading to a new screen. The only way I currently know how to create these types of screens is by creating a new activity for each one, and I'm certain that there is a much less time-consuming way of creating a UI for Android.

Can anyone suggest how to create new screens without creating as many activities?

Lukas Knuth
  • 25,449
  • 15
  • 83
  • 111
africe
  • 5
  • 1
    Using Intent extras, you can pass parameters (e.g., the city name) when launching an Activity to facilitate reuse. See [How to start an Intent by passing some parameters to it?](http://stackoverflow.com/questions/2405120/how-to-start-an-intent-by-passing-some-parameters-to-it) – quietmint Jul 07 '13 at 16:15
  • 1
    Although it might seem like hard work initially, the fragment / action bar / tabs approach is a good general direction to take. – IanB Jul 07 '13 at 16:19
  • what kind of data you shown on the other screen? – Saeed-rz Jul 07 '13 at 16:24

3 Answers3

1

One way would be to use activities and other to use fragments...use of fragments is a bit more complex for a beginner... I don't think there is a shorter way for achieving what you want.

Niraj Adhikari
  • 1,678
  • 2
  • 14
  • 28
1

It's not bad to have that many Activities if they do represent different things. It would eventually be much more cumbersome to have a single Activity represent different things by way of options etc.

Alexander Kulyakhtin
  • 47,782
  • 38
  • 107
  • 158
0

It depends exactly what you mean by "creating new screens". Are you currently doing something like "create one activity for route #29 and another activity for route #20". In that case, passing parameters via an intent is definitely a way to cut down on the number of activities you are making.

However, if you are creating one activity for user input, one activity for city listings, and another activity for bus routes, then I'm afraid that creating activities is one of the only ways to do it. You could go about creating individual pages as Fragments, but that wouldn't really solve your problem, as then you'd just have a bunch of Fragments as opposed to a bunch of Activites.

Think about it this way: if your app was a website, each activity would be a new type webpage that the user would go to. At a certain point, your old webpages just don't have the functionality that you need, so you need to create a new one with new functionality. In the same way, with Android, if you want to add new functionality, you're going to have to add a new Activity/Fragment to get the job done.

One thing to look at, as others have mentioned, is seeing if you can break out any functionality into the Action Bar, but if you're just getting started (which it would appear you are), I'd wait until you have a little more experience managing activites and layouts before you go down that rabbit hole.

Jonathan
  • 3,369
  • 4
  • 22
  • 27