Office Hours — Today, March 2

Friday, February 26

Mar 2
8:25 PM
Mark M.
has entered the room
Mark M.
turned on guest access
NetApex
has entered the room
8:30 PM
Mark M.
Howdy Mr. Apex!
NetApex
Good evening
Mark M.
Or can I call you Net?
NetApex
Net is cool
Once before (it might even have been you) someone told me when I asked them for an idea of an app to make to learn what I am doing... to make something that would be of use to me.
Mark M.
That's certainly standard advice I give
NetApex
So I have started working on an app for my favorite band.
That of course is what what brought up the whole database question I had
If you have no "never do it that way" comments about it, I felt it would be fun to experiment with.
Well.. the fun didn't last lol.
I have come to find I need to learn a lot more about using databases in Android.
Mark M.
The band didn't invite you backstage?
NetApex
First I would like to get the app up and running, then I will accept rewards
Mark M.
I take it you're encountering database problems?
NetApex
It is more of a "I have no clue what I am doing" issue than actual "this isn't working"
And before I get into any of that...
Mark M.
And...I take it the database chapter in _The Busy Coder's Guide to Android Development_ didn't cover what you need
8:35 PM
NetApex
Do you know if it is possible to pull data from a mysql database that is online?
Mark M.
If the MySQL database has a Web service in front of it, yes
NetApex
The database chapter was great on showing me how to create and fill a database, but I made one and was going to pop it into the program and just pull from that... and that is where I got a little off track.
Ok I need to learn how to work on gathering stuff and parsing from the Web
Another question for another time
8:40 PM
Mark M.
Is there anything I can help you with now?
NetApex
Ok question that is relevant for now though. I have the app streaming mp3's off the Internet. I found that if I hit the back arrow to leave the activity that is playing the music, it continues to play...(that is good), but if I try to go back to that activity by clicking on the ImageButton, it starts a new activity (just as it should I suppose) but I need to figure out a way to make it go back to the same instance I guess so people can actually stop the music instead of playing another MediaPlayer over it
Mark M.
If you want the music playing even with no activity, you want the MediaPlayer to be managed by a Service
The activities then tell the Service what to do
NetApex
Ahh ok, I need to look into that then
Mark M.
The built-in Music app works along this model
When you fire up that activity and press Play, it starts a service that does the actual playback
If you BACK out of the activity, the music keeps going and going and going and...
NetApex
and then when they click back on it, it will automatically call the same service instead of starting a new one?
Mark M.
If you fire up the activity again and press STOP, it tells the service to shaddup
NetApex
awesome
Mark M.
There is only ever one copy of any given service running
NetApex
one problem down
Mark M.
(unless there are zero copies)
never more than one of a given service
NetApex
oh ok that is good to know
next question.. is there such thing as too many activities in an app?
Mark M.
Actually, a couple more bits of service-related advice
first
NetApex
ok
Mark M.
There are two chapters on it in the original Android book
Definitely worth reading
NetApex
I will go back over that tonight
Mark M.
You may also want to look at the System Services chapter in the Advanced Android book
8:45 PM
NetApex
ok, anything that can make this smoother I am all for
Mark M.
If you want the fact that music is playing to keep the phone awake, you'll need to hold a WakeLock
That's covered in the System Services chapter
It's referenced there in the context of a somewhat different service usage pattern, but it's still relevant for your case
NetApex
That would have been a question in a few weeks lol
Mark M.
Yeah, well, I thought maybe
NetApex
Hehehe, do you have a Google Wave account?
Mark M.
Yes, though I'm not using it for anything at present
One of those really slick concepts that I haven't figured out where I'd use it
Anyway, back to "is there such a thing as too many activities in an app?"
Could you give me a bit more context?
NetApex
I am using it right now to have my graphics person and my "layout" person look over my app. It makes it easier to show them what I am trying to do and have them say if it makes sense or not.
ok activities
The band has 12 CD's.. eventually I will use one "streaming.java" to take care of it all with variables... but there are other pages too..about, concerts, blah blah... different layouts and things for each so I assume I need different activities to run them all
Mark M.
If they need to structurally look different, they probably should be separate activities
If they have the same structure but different content, they might be different instances of the same activity
8:50 PM
NetApex
Ok, they will unfortunately look different
Your gallery information helped me a LOT with the look for the albums by the way
Mark M.
There aren't too many practical uses for the Gallery widget, but album covers would certainly seem to be one
NetApex
But, I still don't understand how some have the "focused" photo look bigger than the rest
Mark M.
Hmmm...last time I used Gallery (~18 months ago), that happened by default
NetApex
Crap lol
I will see if I changed something in some odd way
I guess now that I look at it, the highlighting does make it look a little bigger
8:55 PM
NetApex
Ok last q:
View paste
g.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
            Toast.makeText(gallery.this, "You clicked : " + position, Toast.LENGTH_SHORT).show();
			if (position == 6) {
					startActivityForResult(new Intent(gallery.this, streaming.class), 0);
			}	
        }
    });
Just a default thing to see if it works as I wanted...
the adapterview passes the number of the album that was clicked.
instead of using the if statement, could I throw a case in there and go through all 12?
Mark M.
sure
NetApex
That could be an answer to a lot of problems then I think
Mark M.
Though if the behavior is going to be basically the same for all, just with a different Intent, I'd make a static array of the Intents and just grab one by index
load up the array in onCreate()
actually, probably not a static array -- just a private data member of the Activity class
NetApex
ok
Mark M.
but a switch() statement works too
NetApex
what I really want is the streaming.class to get a variable from a click in the gallery and show the correct songs accordingly, but that too is another day
Mark M.
Intent i=new Intent(gallery.this, streaming.class);
i.putExtra("somekey", position);
9:00 PM
Mark M.
startActivityForResult(i);
NetApex
son of a gun.. that easy?!
Mark M.
The new activity gets the value via getIntent().getIntExtra("somekey")
yup, very straightforward
If you look at the Android Programming Tutorials, Tutorial #12 shows this technique
NetApex
the more I learn the more excited I get about making tougher things lol
perfect, I know what I will be doing tonight then
Mark M.
BTW, why are you using startActivityForResult()?
NetApex
(looking up how to use switch() and then working on the streaming)
because initially I was receiving crashes on startActivity() and thought that was the issue.. but it wasn't and I forgot to remove it
Mark M.
ha!
ok
NetApex
initially when I went backwards from the activity it would FC
had something to do with how I was trying to buffer the download so it would play ok....hadn't read up on the fact that mediaplayer streams well now on it's own
Mark M.
yes, for compatible URLs
NetApex
ok, did you have a section on the progress bar while playing media thing?
So people can see how long they have for the song, and how much has been buffered?
Mark M.
Oh
9:05 PM
Mark M.
If you look in the Advanced Android book, chapter on Media, I discuss doing that for video with MediaPlayer
same concept should hold for audio
NetApex
ok cool
Mark M.
it'll point you to the vidtry sample app
NetApex
that works for me
thank you
Mark M.
no problem
it's what I'm here for
NetApex
if you do decide to hop on Wave again, I would love to show you how this is all coming together
I promise not to ask a single question there (off the clock)
Mark M.
someday, perhaps
9:10 PM
NetApex
I think that is all I have for right now. You gave me enough to keep me busy for quite a while I think
Mark M.
busy is good, right?
NetApex
Busy is awesome.. keeps me from sitting and crying lol
9:15 PM
NetApex
oh... do you have a chapter on getting rss feeds?
Mark M.
Nope
Just general Internet/HTTP stuff
NetApex
ok I'll use that and work from there
9:20 PM
NetApex
As usual, thanks again for the help!
Mark M.
no problem
9:25 PM
Mark M.
well, if you don't have any more questions, I'll shut the chat down for the evening
NetApex
ok man, have a good night
NetApex
has left the room
Mark M.
turned off guest access

Friday, February 26

 

Office Hours

People in this transcript

  • Mark Murphy
  • NetApex