make instruction activity with multi pages - android

I have already developed my application. But I wanted to give the users a multi-page tutorial, in which you can navigate through using two buttons: Next and Previous.The tutorial is 4 pages long.
My question is, what would be the best strategy to accomplish this?
What I have thought of so far is making multiple activities, however adding four activities to the application seems to be too much for this task. Is there a way to have one activity contain four pages of instructions?
Or should I just replace the current view every time one of the buttons is pressed?
Does anyone have a better idea of what I should do?

Use ViewPager class, it's native and common in most apps.
http://developer.android.com/training/animation/screen-slide.html
example:
http://mobile.tutsplus.com/tutorials/android/android-user-interface-design-horizontal-view-paging/

What you should do is have multiple Activities, use a Button to switch activities, and then have an onClickListener for the button, and then fire an Intent in the onClickListener. This would look like:
Intent intent = new Intent(Activity1.this, Activity2.class);
intent.startActivity();

Related

Android - Usage of multiple activities

I need suggestion on the usage of multiple activities for my application. I want my application to handle about 20-30 physics/mathematical equations. Its like using a listview to allow the user to select the equation they wanna use.
Should I implement in a way such that a new activity opens up for each equation? In other words about 20-30 activities? Is there any other better alternative.
You should use a single Activity, and switch out a Fragment for each of your equations.
So you will have an Activity, and in that layout, a space for the Fragment. Then, you will use the FragmentManager to switch out Fragments when appropriate.
This will be a lot easier to manage than creating a ton of different Activities.
There is a pretty good tutorial on fragments HERE basically Fragments are parts of an activity that can be tacked on to an activity to make it do multiple things. They are very useful if you are programming in Android 4.0 or higher and are much more efficient than the old style of using singular activities for everything.

How to call an activiy itself in android

Basically I am doing a quiz app, I need to dedicate one question to one page, user should be able to flip through the pages to finish one quiz. My proposed idea is to hold a singleton class for all the questions, and have an activity call itself each time for a question, and generate different content according to that question dynamically.But how would one achieve such thing? Can I use intent to call an activity itself? or should there be some other better solutions? thanks
Depending on how many questions you're talking about, the easiest way to do what you're trying to accomplish would be to load up all of your questions into Views and add them to a ViewFlipper. You'd only need one activity, then, and you can animate the transitions between the questions with the ViewFlipper.
You would use startActivity(); or startActivityForResult(); depending on what exactly you wanted to do . Read Here

Starting activity inside the tabhost

I have a tabbased application. On one of my tabs I have a listview with productcells. When the user taps the row a new activity is launched. Is it possible to start the new activity as normal but without "losing" the tabbar at the bottom. Because now my tabbar is gone when I start the new activity. Much like the navigation hierachy on iOS?
This is what you are looking for:
http://blog.henriklarsentoft.com/2010/07/android-tabactivity-nested-activities/
It basically explains how to use ActivityGroup to achieve that effect. I usually don't recommend this approach, not only because sometimes gets a PITA to handle but because it too iPhone-like. Remember, you are developing for Android.
Edit: with regards to Mur's comment... it's not a matter of fanaticism (I even own an iPhone). So what's wrong with doing Android apps in the iPhone way? Basically, the Android OS is not designed to be used in that way. For instance, the nested tabs: using ActivityGroup forces you to handle the back button manually, the activities themselves don't work as they should (what you do with ActivityGroup is getting the Activities' Views and play with them), you have to create public static non-final objects to handle simple things like showing a dialog, etc.
Just saying.

Android 30 Activity, how to make them into one

Lets say, I want to make a quiz application. And I have 90 question - 3 question on each activity which is 30 activity. The way I know how to make all those Activities is to make a class for each of them. 30 class is a lot.
I'm using this method:
startActivity(new Intent(this, Myclass.class));
What is the best way to make all those activities? Or can it all happen in one?
Thanks, comment if something is not explained clearly.
I would try to separate the data (the questions/answers) from the view (the activities) and use some Intent.putExtra() to open one quiz activity with a parameter to let it know which questions to load/show.
I am not sure, but I think that to share the questions data between the activity instances you could put them in a static variable in that activity.
If the plan is to go like start quiz -> good answer -> start another quiz -> ... then you might want to use android:noHistory to avoid leaving all old question activities in memory.
One thing that you could do is use a viewflipper within a single activity, to show a few different views there. Perhaps you could group your questions and use a single activity for each group, using the viewflipper for each group...
bigstones is correct. You need to separate the data from the Activity, and only create a single Activity. Then, you could have a button that they click when they've answered the set of questions they're currently viewing. Clicking that button would show a progress spinner, and then load the next 3 questions in the background. This should all be done with a single Activity.
Mauzam.
I have a better solution .
You could also use one activity ,and use an Expandable List view instead.
this activity will have all the question in it and when someone clicks on a particular question, this list view would expand to show the options and when answer is selected, u can store it somewhere.
here is an example:
http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/ExpandableList1.html
I hope this helps!!

Android setContentView or Intents?

I have a very simple 2 screen android app.
Is there any downside to simply switching out the layouts via setContentView or should i be using intents?Don't want to bugger up my app if something is wrong with this.
Another thing to consider is that activities form a stack. If you want to be able to go back to the previous activity via the 'back' button, then you need to use activity. But if it is something simple like a 'loading' screen when your app starts and you don't have to go back to it again, setting content view would be a much better idea.
Well as stated on Android Dev http://developer.android.com/reference/android/content/Intent.html
An Intent provides a facility for
performing late runtime binding
between the code in different
applications. Its most significant use
is in the launching of activities,
where it can be thought of as the glue
between activities. It is basically a
passive data structure holding an
abstract description of an action to
be performed.
Therefore if your two screens are 2 different applications I would say you want to simply use setContentView.
it will simplify your code when you want to pass info from one to the other views
There is nothing wrong with having two views in a single activity. This approach is more light-weight, as you don't need to go through the phase of stopping one activity and then starting another one. However, it will make your activity code bulkier. Consider now if you are going to need more functionality or more views in the future and if the answer is yes, then it would be better to create separate activities.
If the view is light-weight (a bunch of text boxes), then it should not matter. On the other hand, if the two screens are largely independent and heavy, you could use two different activities. The primary advantages with this approach are:
If there is an error in the second screen (an activity in this case), your application will fall back to the first screen whereas in the case of using the view, the whole application crashes
Better readability
Easier to add more functionality in the future

Categories

Resources