Should I create a fragment for my app? - java

I'm a bit confused as to wether I should create a plain activity or a fragmentactivity. My app is displaying an expandableListView and a dialog. Thats it (pretty much).
I cannot find any instance that my app would be better if I used a fragmentActivtiy because first of all my app is not designed for tablets, and second I'm not adding or doing anything to my main activity during runtime to change the views.
My problem is that it seems it is a must to use fragments, because when I checked out Android dev site on dialogs, it only explains how to implement them using fragments. Are plain activities highly un-recommended or I just have to judge my app, and are all features such as dialogs available for plain activities? (And can someone please give me a link to a good source where I can learn about dialogs in a normal activity?)
http://developer.android.com/guide/topics/ui/dialogs.html
It says here that you should use a fragment but does that mean i have to go all out and make my main activity a fragment?

Here is some discussion about using Fragment or Activity for dialog: Show fragment as a dialog or as a usual activity
If you want to make your dialog as Activity, hope this tutorial helps:
How to create Dialog activity in Android?

A FragmentActivity is an Activity because it extends Activity See here. The question the mean to ask is really a question for your self, do you want your app to support API >= 11 (3.0 Honeycomb) or API >= 4?
In API 11 Android introduced the concept of Fragments to deal with creating apps particularly tablets. But to add support for all the devices still running < 11 they created the Support v4 library which is where FragmentActivity lives.
If you are not using Fragments at all then just use Activity because it's available at all API levels. (it just got added functionality in >=11). If you want to support >=4 and may use Fragments then use FragmentActivity and your covered. I noticed things in the v4 library have started to be deprecated (starting to be phased out by Google). Personally, I won't make a new app with API <14 and suggest you stay above 11.
As far as Dialogs go. You don't need to used a DialogFragment but same question above applies to API level. I typically just used Dialog to show mine even if I'm using Fragments.
Hopefully this clears some things up for you. Happy Codin'

Related

Why Android Studio is creating two fragments?

So here's the problem, when I create a new project using Basic Activity template it generates two fragments and every page or tutorial I've seen it's not generated. Is it something normal? How to I to avoid Android Studio creating this two fragments?
That started in version 3.6 of Android Studio. I believe they're trying to promote their Navigation Component, where the principle is to use one single Activity (host) and many Fragments (for all the other screens of the app).
As the other answers have suggested, you can either select "Empty Activity" instead or delete these fragments after they're created.
My suggestion would be to try and learn about the new Navigation Component, as it might become the new Standard in the near future.
I honestly don't know why Android Studio does that but if you want just one activity you can start with "Empty Activity" Or just "Add No Activity" option. And then add an activity with the App->New->Activity->Empty Activity.

What is fragment_main?

I've recently setup eclipse and the android SDK on a new computer but I fear something has gone wrong when setting it up.
When I create a new android project with a blank activity two files I've never seen before appear:
fragment_main.xml
and
appcompat_v7_2
What are they and do I need to worry about them?
appcompat-v7 :
As stated in Android's Support Library Overview, it is considered good practice to include the support library by default because of the large diversity of devices and the fragmentation that exists between the different versions of Android (and thus, of the provided APIs)
Reference : Why does Eclipse automatically add appcompat v7 library support whenever I create a new project?
Fragment_main :
fragment_main.xml is the Layout for the fragment.
Refer this : Building a Dynamic UI with Fragments
hope this helps
The first, let read code in MainActivity!
You can see fragment_main is layout of one fragment in it.
when application running, fragment will be added to layout and show this layout.
Let read more about here for understanding about fragment. It is very important if you want to make android app.

Fragment transition?

Any help would be great with my issue. Basically I'm using this tutorial and its a web view fragment. So I got rid of the WebView and made new activities. My issue is connection the activities with the drawer so then every thing goes to a different activity. Once again, any idea on how to do this would be helpful.
I would recommend this tutorial instead.
http://www.androidhive.info/2013/11/android-sliding-menu-using-navigation-drawer/
I've used it and I have a functioning application at the moment. You can download the source, change the text and images if you'd like.

First android app for iOS developer

i am iOS app developer. Now when i created an app on iOS i want to do the same on android. With java i was familiar just now need some time to remember.
i was looking at some tutorial how to do one or other things. But what i can't find is the basics how everything works. How classes is interacting with each other.
For example i want to create registration window with few buttons and alerts.
I want registration window to be called just once when app is installed and just that.
Should i create new java class and few layouts, one for View with buttons and other for Alerts ?
Or should i create other class for alerts if i need them in other flow of my app ?
And how i should call that window with registration from my main class, which is
extends Activity
Also if there are some developers who came this road from objective-c (iOS) to java (android). It would be nice for some share experience how they did that.
Thank you for any help :)
Very few of the concepts in iOS and Android are similar. On Android you have Activites, Intendts the Manifest. When you design your layout it should be resolution independent. You have a search, back and a menu button and variable hardware. All of this has no equivalent in iOS.
That said, I think you just have to read the basic concepts and the getting started guide no matter if you come from iOS or never have done mobile development before.
EDIT
To answer your concrete question. Take a look at the lifecycle of an Activity and Preferences. With this, you could do some action on the first start of your main Activity and store some flag in the preferences when it's done. On the next start you just test that preference and skip the logic.
You can create one activity (.java file) and one layout(.xml file with buttons and input boxes) , alerts could be toast notifications:
http://developer.android.com/guide/topics/ui/notifiers/toasts.html
All you require for this is a activity and a layout xml for that activity, this activity will be your main ie the entry point to your application, in that activity oncreate method you can check if it is registered or not by setting a flag or something which will direct to the next activity if its registered.
GOOD LUCK...
Just like your nibs in iPhone you create xml layouts in Android. And for view controllers here you make activity. One important thing is AndroidManifest.xml file, it contains all information of your app (like plist) plus all the activity information(Intent type and launcher methods).

Android app UI design

I'm just trying to make an android app design similar to the one in the link below.
http://itunes.apple.com/gb/app/id406490694?mt=8
how would I go about making a multiple page application like this? I've only ever worked on single page applications so any advice you have would be great.
How would I make the buttons at the bottom change the page etc?
Thanks,
David
This app was designed for ios. You should make your app native to the android platform. Otherwise you will be spending a lot of time performing hacks to get the UI to look the same. You may keep some of the design but focus more on how to make this app look great for android.
In terms of switching "screens" you will need to declare each activity in the manifest like so...
<activity android:name=".YourClass"
android:label="#string/app_or_class_name" />
Then when a button or event is triggered you can use the following to load up that screen or activity.
Intent nextIntent = new Intent(v.getContext(), YourClass.class);
startActivity(nextIntent);
you should use tabActivity for this purpose with tabs at the bottom.
http://developer.android.com/resources/tutorials/views/hello-tabwidget.html
I have very little android programming experience, But I think I can point you in the right direction.
http://developer.android.com/guide/topics/fundamentals/activities.html
specifically look down the page a little at "starting an activity"
It appears that tabActivity is deprecated, so.... I wouldn't use it. The dev guide points to Fragments as an alternative:
http://developer.android.com/guide/topics/fundamentals/fragments.html
good luck, and I hope someone else answers that knows a little more about it...

Categories