Fragment Tab-Pager - Android Software Development

I am having trouble implementing the Pager and TabsPager from the examples into my apps. Has anyone successfully (besides the Google Devs) implemented these into their apps? I'm also wanting to know how to make fragments (necessary for the ViewPager). Every attempt I've done ends in force closes. Can anyone help? Thanks in advance

Related

Adding ads to form

I have seen some apps which have ads a the botting of it's form.
Is there a way to implement it?
Can someone show me a snippet of give some directions?

[Q] Android app auto starts again when device rotated

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

Programming help with views

I could use some help with an app I'm working on. I need to know how to control the views and work with which things are in focus. I also want it to work even while in the background so using a handler or something else is knowledge I could use help with. I've been sifting through the javadoc and multiple other forums and am pretty much stuck. Anyone with decent knowledge that would be willing to help me out should message me. Thanks in advance.
First I would move this to the Android dev forum
Android uses Intents to display and run processes. Activities are Intents (views)that you can actually see on the screen and Services are Intents that can be run in the background.
Starting on the Android dev site is really the best place to find the answers to the problems.
That and using the Android examples that come with the SDK. Good luck and I hope you were talking about Android! XD
I was talking about android so here's what i'm trying to do. I want to take in trackball movements and pretty much make it so they don't affect my program or others. I'm not sure how to make it so that requestFocus() will take whatever view is currently on the screen, capture it, and pretty much revert right back to it if the trackball is used. I've tried a lot of different things, but I have been stuck on this forever. Anyone know how to accomplish this because for the most part I think that the trackball is not documented all that well. Any suggestions would be great!
I would look at the http://developer.android.com/guide/topics/ui/ui-events.html , onTrackballEvent(MotionEvent) . You should be able to override that in your service, and just process the motion however you want and not call super.onTrackballEvent();
The problem is that although onTrackBall does captures events, it does not capture all of them. In the docs it says that the method will handle all events not already handled by a view. So I guess my question overall is how do you do just that? Take in every trackball movement no matter what view is reading it? Whether it be another app or anything else. How would I capture the remaining movements?
So after a bit more research here's what I've come up with for what I need to do. Either access the event queue or make it so any time the trackball is used, whether on the homescreen or something else, my application will be able to take these events and manipulate then as i need to. So anyone willing to help with this? I figure I need to make a thread, but how do I get it to read in other applications readings? Is this even possible?

[Q] Detecting homescreen

Hey guys,
In an effort to 'hack' the Sense homescreen to use a custom launch/shortcut bar, I am creating an app that needs to know if the homescreen is currently visible. With this, I need some help.
I've been looking at four possibilities to do this:
1. constantly poll the window manager for the current activity. This works, however my battery doesn't like this and it's generally bad practice.
2. Use a widget to tell the service wether it's active. Too bad, Android doesn't seem to provide some kind of event to a widget when the homescreen is opened. Strange though, as you'd say this would be very useful when updating widgets. Am I overlooking something?
3. Watch the logcat or message broadcast. This works nicely to intercept a user moving away from the homescreen at it will output this when switching activities:
08-22 12:25:28.891: VERBOSE/HtcAppUsageStats(255): (launch app, package): (People, com.android.htccontacts)
I think I could intercept that, but then there's another problem. Pressing home broadcasts this message for com.htc.launcher, however using the back key (or even software options) to move back to the homescreen do not invoke this.
4. Intercept hardware presses. This seems rather hard when you don't want to actually do something with the presses. This combined with the above method would give me a decent way to see if the homescreen is active.
But all of those methods just don't work the way I want them to. Anyone got a clue on how to accomplish this? I don't mind if I require root access or some dirty programming, by the way. After all, it's some sort of a hack.
A push in the right direction would be very welcome
Quick kick. No one knows a solution for this?
Sent from my HTC Sensation Z710e using XDA App
If this is just for sense, have you checked the openSense sdk?
From something awesome
I haven't really looked into this, I also have no experience with widgets, but using my general knowledge in how Android works, concerning 2), does the widget not receive a visibility change? I know for LiveWallpapers there is a void VisibilityChanged(boolean visible) method that allows it to update when visible. Do Widgets not have this?
killersnowman said:
If this is just for sense, have you checked the openSense sdk?
From something awesome
Click to expand...
Click to collapse
Couldn't find the documentation of it. But it must be somewhere, this is indeed another option to look into.
Metastable said:
I haven't really looked into this, I also have no experience with widgets, but using my general knowledge in how Android works, concerning 2), does the widget not receive a visibility change? I know for LiveWallpapers there is a void VisibilityChanged(boolean visible) method that allows it to update when visible. Do Widgets not have this?
Click to expand...
Click to collapse
I've tried all the event listeners I could find in the reference. I don't remember the VisibilityChanged method thou, will look into that tonight. Otherwise I might be able to build a Live Wallpaper and hook it to a service.. Interesting
Thanks both!

[Q] Adding Events to Caldroid

Hey there everybody,
I needed a calendar library that would help me add custom events from my server to the app.Searching around for it and I Found ExtendedCalendarView and Caldroid, However, ECV doesn't support androids below API14.Leaving me with Caldroid.
I Was amazed to see how easy it was to implement it in my app but I wasn't able to do what I wanted it for.Add custom events.
I Read the documentation and figured that there are no functions for doing that and we have to implement it ourselves.
So i tried adding it but i failed in even assigning a custom background for a date.I Tried various methods and sometimes it did nothing and sometimes it just crashed.
Can anybody help me with setting custom events to it?
caldroid events
hi, how do you make the events using caldroid? thankyou.

Categories

Resources