Hi,
I'm trying to replicate an iOS app in Android. I have tab up an activity that holds 4 different fragments, and these are loaded using the .replace() method, depending on which tab is selected.
That's all fine. Working as intended.
My issue is that these 4 tabs also lead to other fragments (in my attempt to replicate iOS pushing view controllers within a tab). These fragments have to be native to the tab that they are loaded from. The problem is that if I load one of these fragments and then change tab the app tends to die rather quickly. Does anyone have any recommendations about how to achieve what I'm after?
tl;dr: Here's a simple diagram in case my question isn't very clear:
MainActivity (Holds tabs (4 different tabs))
- Tab1 -> TabFragment1
- Tab2
- Tab3
- Tab4
So: TabFragment1 needs to be local to Tab1. If I load up TabFragment1 and switch to Tab2, and then switch back to Tab1, I would like to have TabFragment1 still active.
Thanks in advance!
Related
I'm learning how to program in android and want to make a musicplayer. The problem I have now is I have no idea how to build the views for the application. For example if you start the application you have the options, all songs, artists, albums. If you then select artists you get all the albums from that artist, if you select an album you get the songs etc..
Now my problem. Do I have to make a different activity per view (all songs view, artist view, album view), because they all do almost the same, just fill a listview with some data.
Can sombody point me to a tutorial of give me a hint how to do this because I'm trying to find a solution for 2 weeks now and all 101 "noob" basic tutorial I found don't cover this.
Thanks in advance.
Nobody who can point me to the right direction?
I would create a new activity for each, but create a base class that has the listview in it. Then in each new activity, just inherit from that base class and call a method to fill in that list view with the data specific to that particular activity.
-frank
Sent from my PC36100 using XDA App
Hello!
I'm only new to android development too but I'd suggest two things. Firstly you need to make sure the music playing is being done by a service so it works in the background. Secondly, I don't think you'll need a different activity for each view. List views are populated by adapters if I remember right so maybe one view to choose the music filter and the next view will choose the correct adapter and populate the list....
Hope this helps a little.
Sent from my X10i using XDA App
@kaediil, I think I try that, I'm open for other suggestion tho.
@Keithod, the mechanics to play a song are already done, the vies are the only problem. And I tried it with adapters but how am I'm going to handle the onclick then? That would be one hell of a switch statement.
Is there a tutorial that handles these kind of problems?
If your music player created a database of the metadata, artist, album etc. Then your adapter could use the ID of the element that was clicked as the criteria for the select statement... No switch required and only one activity...
Sent from my X10i using XDA App
I now get the id3 tag from the song and build the views that way, I could dump it in a database when the application start. Let me try that.
After a couple of days I am still stuck, I prefer a tutorial or a snippet how I could fill 1 listview and when I click a specific item another listview or the same will be filled with other items.
Hope somebody can help me with this.
What went wrong with the database idea?
Sent from my X10i using XDA App
Then I still have to display it, or it's from an arraylist or database.
Try using a ViewFlipper: http://developer.android.com/intl/zh-CN/reference/android/widget/ViewFlipper.html
You don't need to have one Activity for every view, you can choose to display different info depending on the previous Screen or if the user has clicked a different button.
An example:
- An user clicks on a button that goes to PSN and recover a list of latest games played by the user with his playstation.
- You put a flag on the Bundle Extras to indicate to the next ListView activity that you want a PSN info.
- In the ListView Activity you recover info from PSN. If the user clicks on the Xbox Live button you use the same Activity to query Microsoft's website. You can even load a different XML Layout for PSN or Xbox Live in that same Activity and have 2 completely different Layouts for a single Activity:
Code:
if (xbox)
setContentView(R.layout.achievements_xbl);
else
setContentView(R.layout.trophies_psn);
Anyway, if the methods are not shared to display different info in the Activities is a good practice to have different Activities Classes, you can have one XML Layout if the List Rows are similar and use in two different Activities.
Helper Classes, to separate business code from Activities are also a great tool.
Hello all,
I've written a simple audio player app and testing it in Samsung Galaxy S.
It is a simple app with can create playlist and some buttons to play the mp3 file.
However, there's a funny bug in it.
After starting the app, whenever I rotate the phone, the running app will launch another instance of the app. If I rotate again, another instance (3rd) would be started. So u can hear 3 copies of the same audio being played simultaneously.
What could be wrong with it?
Is there some code which can prevent program re-entry?
Thanks.
It's not a bug, that's the way andorid OS works. You need to account for this in OnCreate for your activity. I assume you are spawning off the actual playing of the MP3 in a thread or service. You need to check if the service is already running in OnCreate and attach, else spawn a new one.
Hello Gene,
How do I check if an activity is already running?
I could not find the answer on the android developer page (the topic on application fundamentals).
And no, I'm not converting it to a service yet as this is my first app.
Haven't explore service yet.
Thanks.
I read on another article, a simple way to prevent this is to add overwrite the onConfigurationChanged function
@Override
public void onConfigurationChanged(Configuration newConfig) {
//ignore orientation change
super.onConfigurationChanged(newConfig);
}
and modify the androidmanifest.xml
<activity android:name="selectCategories" android:configChanges="orientation|keyboardHidden"></activity>
But it still launch multiple instance of the app.
Thanks.
This is a good question and should be in an FAQ somewhere.
As already mentioned, changing the display orientation basically restarts your app. Read the Android dev page on Activity lifecycle for more info.
A short answer for your question is: the Bundle parameter for onCreate() will be null when your app is first run. When your app is paused and restarted, that Bundle will be non-null. You can store data in that Bundle by overriding onSaveInstanceState(), then check for that data in onCreate(). It's a good idea to learn how to do this (save/read app data on pause/restart). Once you start testing apps by rotating the display at various times, you'll find a lot of them FC at unexpected places.
This is indeed a topic that keeps surprising people who are new to android (ahem, like me 4-5 months ago ).
The solutions above are perfect, however in certain situations there's another trick that might make your life much easier. I suspect it won't help you in this case, but it might help others who tackle the problem and see this thread.
Certain applications, mainly games, should be fixed in a single orientation. I.E. you won't be playing angry birds on portrait - that game is locked to landscape, as it should be. In order to lock your activity in a certain orientation you add this attribute to the manifest under the Activity tag. So a standard activity might look something like that, combined with the ignore tag from the previous posts:
Code:
<activity android:screenOrientation="landscape" android:configChanges="orientation|keyboardHidden"
android:name="whatever">
The great thing about this combination is that your activity will not restart at all when the phone is rotated. Of course, for a standard activity you'd usually want to support both landscape and portrait, but if you need your app to be in a fixed orientation this is the way to go - no weird FCs or annoying bugs
Hi,
How do I check the bundle?
And also, what to do if the bundle is not null? Just return?
Thanks.
regards
r_p_ang said:
This is a good question and should be in an FAQ somewhere.
As already mentioned, changing the display orientation basically restarts your app. Read the Android dev page on Activity lifecycle for more info.
A short answer for your question is: the Bundle parameter for onCreate() will be null when your app is first run. When your app is paused and restarted, that Bundle will be non-null. You can store data in that Bundle by overriding onSaveInstanceState(), then check for that data in onCreate(). It's a good idea to learn how to do this (save/read app data on pause/restart). Once you start testing apps by rotating the display at various times, you'll find a lot of them FC at unexpected places.
Click to expand...
Click to collapse
I am developing an android app that utilizes a TabHost and tabwidget. When I run the app on my virtual phone (target 1.6) the tabs show up fine (visually) and act just fine.
When I run it on my android phone (version 2.2) the tabs seem to disappear; leaving only the text behind. It is almost as though the pictures of the tabs can't be found and are replaced with black.
Edit:
for some reason xda thinks that I am trying to submit a link and denies me from posting the xml... I'll edit this once I figure out how to post the xml with the corresponding view.
I just purchased and successfully rooted (thank you experts here) my Nook Simple Touch.
I would like to create a streamlined reading experience between my Nook ST (where I will do majority of my reading), and my Galaxy S3 (which I will read while on the bus / in lines / etc). This is in fact why I purchased my own root-able Nook rather than continuing to side-load and use my girlfriend's kindle.
I have searched extensively and not come up with any solutions. The current Moon Reader Pro is not supported by the Nook ST, and reading others' posts it seems it does not work very well anymore even if you can find a place to download the old version apk's (http://forum.xda-developers.com/showthread.php?t=1687208&highlight=sync+last+read+page)
I have tried PageTurner, which does not allow you to make notes or bookmarks, but at least is supposed to sync last page read, but it's not working for me across devices.
It seems like this really would be a common feature users would desire, has anyone found a good way to accomplish this?
Thanks for the help!
Forgot to say, I have also tried FBreader, but this would require me to root my Galaxy S3, and I have no other reason to want to do that at this point in time, so prefer a different option.
Found some solutions.
1.) Page Turner
This is what I settled on. The sync does in fact work, what I had to do was delete every book off my device first. Then on Calibre, change the settings so it would automatically manage the metadata (on each connect) on my devices. After doing this I re-uploaded the books to my phone and Nook Simple Touch, allowing Calibre to manage these devices. Since doing this, the sync feature has worked well.
Pros:
-best, most crisp display of any of the readers I have found which are capable of syncing
-sync feature works smoothly (after loading as above)
-developer of this software is very active and responsive
-the objective developer states for designing this software is consistent with my purpose - open platform for reading DRM free ebooks smoothly on multiple devices
Cons:
-does not support custom bookmarks or notes (I am told this is planned for the next version, but timeline is not certain)
-control of interface leaves room for improvement (have to navigate through cumbersome menu to adjust font size, can't put in all the cool finger swipe controls that Moon Reader has), however, as my GF put it, the purpose is to read not to have fancy controls, and bottom line is once I get the settings adjusted the way I want, this offers the most crisp, best visual reading experience.
2.) Moon+ Reader Pro (old version, can get the old APK that Nook will accept)
I was able to get this sync feature to work after clearing device content and re-uploading with Calibre managing devices and meta-data, as described above. Not sure what problem the people in the thread I linked to in my original post were having, but I did not have this problem when using the same version on both my phone and nook.
Pros:
-syncs
-amazing control options (adjust font by sliding up and down side, assign swipes across page to various functions - I liked left to right and vice versa for skipping ahead or back by chapters, swipe up to close app, swipe down to return to bookshelf), very feature rich
-allows for notes and bookmarks
Cons:
-display is horrible on Nook! absolutely terrible. This was the deal breaker for me, as even though I loved the ability to customize and control the interface, the fuzziness, lack of contrast and crisp screen was unacceptable for prolonged reading.
-the developer is not currently interested in supporting the Nook, so there will be no updates which will change anything. All the development is going into versions that will not run on the Android 2.1 (which nook uses)
3.) Aldiko using Aldiko sync
I must confess I did not try this very hard. I downloaded the latest version of Aldiko which the Nook would support, and found the control of the interface as well as quality of visual display to be inferior to the other two options.
However, you can make this work I believe. You need the separate app aldiko sync. Unfortunately, in the more recent versions (which are not supported on Nook), you need to have root access to the device (something I was not interested in doing on my phone). I did get it to work by loading the old APK, which did not require root access for aldiko sync, and this did work. But as above, I found this option inferior to both of the others.
Hope that helps anyone else with the same questions I had. I would like it if Page Turner would become more feature rich, the very most important feature needed being support for note taking, and custom book marks.
Okay, so I've been surfing the web for a few weeks/months now but I can't seem to find any decent tutorial for my query.
With high hopes, can anyone show me how to do it on a single activity with at least 10 questions each?
I'm currently developing an M-Learning application. So aside for all the reading materials and somewhat simulations,
I need to present a quiz that will ask users at least 10 - 15 items per chapter.
I'll be presenting it on a graph as well for the user's profile. (But that's another issue I'd tackle later on)
Currently, all I have now was moving from one activity to another and vice versa.
Can anyone please guide me? I'd modify this if it doesn't clarify anything.
Please take interest. Am still a student though.
iamreverie said:
Okay, so I've been surfing the web for a few weeks/months now but I can't seem to find any decent tutorial for my query.
With high hopes, can anyone show me how to do it on a single activity with at least 10 questions each?
I'm currently developing an M-Learning application. So aside for all the reading materials and somewhat simulations,
I need to present a quiz that will ask users at least 10 - 15 items per chapter.
I'll be presenting it on a graph as well for the user's profile. (But that's another issue I'd tackle later on)
Currently, all I have now was moving from one activity to another and vice versa.
Can anyone please guide me? I'd modify this if it doesn't clarify anything.
Please take interest. Am still a student though.
Click to expand...
Click to collapse
Since you have a quiz app I'd recommend a swipe view with 4 radio buttons and a spinner with the chapter in the action bar or chapter list in the navigation drawer. Use 1 fragment and dynamically change the text for each fragment and inflate the swipe views. That way lesser resources.
Sent from my Moto G using XDA Free mobile app
Hi there once again.
I was able to pull off the Swipe View. However, I wanted to ask if this scenario is possible.
I wanted to build the quiz in a single activity only. Is this possible?
Button A ---> QuizActivity(Set1)
Button B ---> QuizActivity(Set2)
I want the quiz to happen on a single activity only but with different set of questions as triggered by different buttons.
Is this possible? And how will I pull this one.
Thanks.
So you want to have a set of buttons and depending on the button (category of questions) clicked you want to start a quiz of that category?
Simple answer to your question though is yes, u can have a quiz in a single activity if you wish.
Sent from my GT-I9300 using XDA Free mobile app