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!
|
Mark M. |
how can I help you today?
|
Mark S. |
Howdy Mark! A pleasure to be here....
|
Mark S. |
I have a client with an existing Android app, and
they want to incorporate a simple game. This probably means no
additional game libraries...
|
Mark S. |
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.
|
Mark S. |
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.
|
Mark S. |
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?
|
Mar 19 | 10:05 AM |
Mark M. |
what is your android:minSdkVersion?
|
Mark M. |
(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
|
Mark M. |
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
|
Mark M. |
certainly, animators translate a collection of widgets
|
Mark M. |
one presumes they can scale them as well
|
Mark M. |
anyway, I'll swing back to you shortly
|
Mark M. |
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
|
Mar 19 | 10:10 AM |
Marcin |
I have activities a,b,c
|
Marcin |
a and b are responsible for logging in..so the flow goes like this a->b->c.. and the whole app is inside c
|
Marcin |
when I open the app (c) (with some fragments) and then press home.. and kill the pid from adb
|
Marcin |
then I run the app.. which is going to recreate
|
Marcin |
first i recieve oncreate for the fragment then for activity c
|
Marcin |
the hack is .. that in case of recreation i want to restart the whole app
|
Marcin |
back to a
|
Marcin |
so I do something like finish();return; inside activity c onCreate
|
Marcin |
if savedinstancebundle is not unll (i know its ugly)
|
Marcin |
the problem is that the fragment is still alive for a bit (its oncreateview fires).. and right after it there is ondestroy
|
Mar 19 | 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
|
Mark M. |
try android:clearTaskOnLaunch="true" on activities b and c
|
Mark M. |
on <activity> element in manifest
|
Mark M. | |
Mark M. |
"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."
|
Mark M. |
I will swing back to you in a bit for follow-up or other questions
|
Mark M. |
Mark: do you have another question?
|
Marcin |
thanks Mark, will try that
|
Mark S. |
Yes, regarding my embedded game...
|
Mar 19 | 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
|
Mark M. |
however, I am not aware of a general-purpose implementation of that
|
Mark M. |
game frameworks have theirs
|
Mark M. |
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.
|
Mar 19 | 10:25 AM |
Mark M. |
I've considered rolling such a tiling engine myself, but I have never had the itch to scratch
|
Mark M. |
and so it's buried among 18,000 other to-do items
|
Mark S. |
Please keep us informed.
|
Mark S. |
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
|
Mark M. |
anyway, I'll swing back to you in a bit
|
Mark M. |
Marcin: do you have another question?
|
Marcin |
still testing
|
Marcin |
..
|
Marcin |
go ahead Mark
|
Mark M. |
ok
|
Mark M. |
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
|
Mark M. |
if either of you come up with a question, just chime in
|
Mark S. | has left the room |
Mar 19 | 10:35 AM |
Marcin |
seems like I should place it on A, right?
|
Marcin |
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
|
Mark M. |
my apologies
|
Marcin |
hmm doesnt seem to work.. even if i dont kill the pid.. just press home and launch it again
|
Marcin |
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
|
Mark M. |
it is all very mysterious
|
Mar 19 | 10:40 AM |
Mark M. |
did you remove clearTaskOnLaunch from b and c, per my incorrect suggestion earlier?
|
Marcin |
y
|
Marcin |
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
|
Mark M. |
some apps just go straight to LoginActivity
|
Marcin |
.. regarding recreation lifecycle.. isnt it strange that fragments onCreate is invoked before activity onCraete?
|
Mar 19 | 10:45 AM |
Mark M. |
no
|
Mark M. |
that's why there is onActivityCreated()
|
Mark M. |
onCreate() and onCreateView() can happen before/during onCreate() of the activity
|
Marcin |
yes u r right
|
Marcin |
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
|
Marcin |
within activity a ?
|
Marcin |
sorry
|
Marcin |
... mmm
|
Marcin |
i might actually .. looking at code..
|
Mar 19 | 10:50 AM |
Marcin |
seems like i can... testing
|
Marcin |
it reaches activitycreated and crashes.. but that was a good hint
|
Mar 19 | 10:55 AM |
Marcin |
Mark what is a definition of Task from android:clearTaskOnLaunch
|
Marcin |
?
|
Mark M. | |
Marcin |
its a flow of activities right?
|
Mark M. |
correct
|
Mark M. |
the back stack represents a task, in effect
|
Marcin |
Thanks for your help Mark
|
Marcin |
bye
|
Mark M. |
the transcript will be archived on http://commonsware.com/office-hours/ shortly
|
Mark M. |
next chat is Thursday at 4pm Eastern
|
Mark M. |
have a pleasant day!
|
Marcin | has left the room |
Mark M. | turned off guest access |