Office Hours — Today, March 19

Thursday, March 14

Mark M.
has entered the room
Mark M.
turned on guest access
Mar 19
10:00 AM
Mark S.
has entered the room
Mark M.
hello, Mark!
how can I help you today?
Mark S.
Howdy Mark! A pleasure to be here....
I have a client with an existing Android app, and they want to incorporate a simple game. This probably means no additional game libraries...
Essentially, the game consists of a static background image - a scene - with animated characters at certain positions in the scene. The characters do not move from their x/y positions, but they each have simple animations.
My thought was to create each character as an image button, with the 2-step animation defined (in a separate animation XML), and used as the background to the image button. So far, pretty simple.
But the complicating factor is - the client has asked that the scene be pinch-zoomable.
Marcin
has entered the room
Mark S.
I think the pinch-zoom requirement might make my simple image button approach moot. I don't there's a way to scale a layout and the child components of the layout. Your thoughts?
10:05 AM
Mark M.
what is your android:minSdkVersion?
(BTW, hello, Marcin -- be with you shortly!)
Mark S.
You are good. At the moment the minSdk is down to 8, but I might be able to make the argument of bumping that up.
Mark M.
yeah, if you can get it to 11 -- or only support the game on 11+ -- you could use the animator framework to scale the whole game, conceivably
not sure how good it'll look
Mark S.
Interesting. The animator framework might be able to scale all the components? I have a nother question, but I will defer to Marcin.
Mark M.
I have not tried scaling a collection of widgets, but it's not out of the question that it'll work
certainly, animators translate a collection of widgets
one presumes they can scale them as well
anyway, I'll swing back to you shortly
Marcin: do you have a question?
Mark S.
Perhaps I should experiment. Can you think of any examples out there? I'll ask a question or two later about tiling...
Marcin
Hi Mark, yes
10:10 AM
Marcin
I have activities a,b,c
a and b are responsible for logging in..so the flow goes like this a->b->c.. and the whole app is inside c
when I open the app (c) (with some fragments) and then press home.. and kill the pid from adb
then I run the app.. which is going to recreate
first i recieve oncreate for the fragment then for activity c
the hack is .. that in case of recreation i want to restart the whole app
back to a
so I do something like finish();return; inside activity c onCreate
if savedinstancebundle is not unll (i know its ugly)
the problem is that the fragment is still alive for a bit (its oncreateview fires).. and right after it there is ondestroy
10:15 AM
Marcin
is there a way to disable fragment recreation?
Mark M.
no
Marcin
any way of setting the activity recreation to start with activity a?
Mark M.
possibly
try android:clearTaskOnLaunch="true" on activities b and c
on <activity> element in manifest
"When the value is "true", every time users start the task again, they are brought to its root activity regardless of what they were last doing in the task and regardless of whether they used the Back or Home button to leave it."
I will swing back to you in a bit for follow-up or other questions
Mark: do you have another question?
Marcin
thanks Mark, will try that
Mark S.
Yes, regarding my embedded game...
10:20 AM
Mark S.
I haven't loaded all the images up yet, but I have a suspicion that the combination of my background image and all my image buttons might get me into a memory issue...
Mark M.
well, those images on the buttons shouldn't be that big
Mark S.
So, my thought is to try some sort of tiling mechanism, to only display a portion of the entire game scene that's some what in line with the current viewport.
Mark M.
that's certainly one possibility
however, I am not aware of a general-purpose implementation of that
game frameworks have theirs
map engines have theirs
Mark S.
True. I might be overestimating the required memory. If each button is 8k (4k * 2 for a 2-state animation), and I have 25 buttons, maybe that's not so much.
Mark M.
bear in mind that file size on disk != heap space consumed
Mark S.
Good point.
Mark M.
heap space = # of pixels x 4 (for ARGB888)
Mark S.
I will note that. I am now thinking there may be clever ways to make the background image smaller. But I understand that there is not a generic "tile these images for me" approach.
10:25 AM
Mark M.
I've considered rolling such a tiling engine myself, but I have never had the itch to scratch
and so it's buried among 18,000 other to-do items
Mark S.
Please keep us informed.
BTW, when will the "CommonsWare" hats and mugs be available?
Mark M.
shortly after somebody convinces me that it's a good idea to have hats and mugs, I suppose
anyway, I'll swing back to you in a bit
Marcin: do you have another question?
Marcin
still testing
..
go ahead Mark
Mark M.
ok
Mark: back to you, if you have another question
Mark S.
I will make a note to remind you about the mugs. In the meantime, I'm good for now. Thanks!
Mark M.
OK
if either of you come up with a question, just chime in
Mark S.
has left the room
10:35 AM
Marcin
seems like I should place it on A, right?
Suppose, for example, that someone launches activity P from the home screen, and from there goes to activity Q. The user next presses Home, and then returns to activity P. Normally, the user would see activity Q, since that is what they were last doing in P's task. However, if P set this flag to "true", all of the activities on top of it (Q in this case) were removed when the user pressed Home and the task went to the background. So the user sees only P when returning to the task.
Mark M.
oh, yes, you are correct
my apologies
Marcin
hmm doesnt seem to work.. even if i dont kill the pid.. just press home and launch it again
it is still on c
Mark M.
this is one of the reasons why I haven't written a chapter on tasks yet, though eventually I need to
it is all very mysterious
10:40 AM
Mark M.
did you remove clearTaskOnLaunch from b and c, per my incorrect suggestion earlier?
Marcin
y
regarding a StartNotLoggedinActivity (a) -> loginActivity (b) -> MainActivity (c) .. is this a reasonable pattern?
Mark M.
assuming that StartNotLoggedInActivity is delivering value to the user, sure
some apps just go straight to LoginActivity
Marcin
.. regarding recreation lifecycle.. isnt it strange that fragments onCreate is invoked before activity onCraete?
10:45 AM
Mark M.
no
that's why there is onActivityCreated()
onCreate() and onCreateView() can happen before/during onCreate() of the activity
Marcin
yes u r right
Im refactoring someones app.. on activity c recreation / onCreateView of a fragment is invoking a call via an object which requires activiy A to be up.. (and it is not since recreation)
Mark M.
can you move that to onActivityCreated()?
Marcin
so the app always crashes on recreation
within activity a ?
sorry
... mmm
i might actually .. looking at code..
10:50 AM
Marcin
seems like i can... testing
it reaches activitycreated and crashes.. but that was a good hint
10:55 AM
Marcin
Mark what is a definition of Task from android:clearTaskOnLaunch
?
Mark M.
Marcin
its a flow of activities right?
Mark M.
correct
the back stack represents a task, in effect
Marcin
Thanks for your help Mark
bye
Mark M.
the transcript will be archived on http://commonsware.com/office-hours/ shortly
next chat is Thursday at 4pm Eastern
have a pleasant day!
Marcin
has left the room
Mark M.
turned off guest access

Thursday, March 14

 

Office Hours

People in this transcript

  • Marcin
  • Mark Murphy
  • Mark Semsel