Oct 20 | 7:25 PM |
Mark M. | has entered the room |
Mark M. | turned on guest access |
Oct 20 | 7:30 PM |
yuku | has entered the room |
Mark M. |
howdy, yuku!
|
yuku |
Hi Mark
|
Mark M. |
how can I help you today?
|
yuku |
long time didn't see the chat room
|
yuku |
I've a question..
|
yuku |
I'm using c2dm to receive notifications from server, and when I receive it, I put a notification status bar
|
Oct 20 | 7:35 PM |
yuku |
View paste
|
yuku |
and that Intent also contains an extra to let the root activity knows which activity to open on top of it
|
yuku |
hope that makes sense?
|
Mark M. |
so far, yes
|
yuku |
ok, so, let's say the root activity has opened screen A due to the user tapping on the notification.
|
yuku |
*i mean activity A
|
yuku |
then, the user navigates to other activities.
|
yuku |
the problem I'm seeing is, when the user switches
to another application, and back to my application, my application shows
activity A instead of the last activity the user was using.
|
yuku |
the behavior is as if the user clicked on the notification *again*.
|
Mark M. |
how does the "user navigate to other activities"?
|
Mark M. |
are you using FLAG_ACTIVITY_NEW_TASK on those too?
|
Oct 20 | 7:40 PM |
yuku |
I mean the user dismisses activity A or opens other activities. No, I don't use any flags to open the other activities.
|
Mark M. |
so, you are starting Root (via the PendingIntent),
Root starts A (with no flags), A starts B, B starts C, ... (all with no
flags)
|
Mark M. |
then user presses HOME
|
Mark M. |
then user long-presses HOME to return to your task
|
Mark M. |
and they wind up back at A and not at C (or wherever)
|
Mark M. |
right?
|
yuku |
yes!exactly
|
Mark M. |
does this happen all the time?
|
Mark M. |
for example, if the user presses HOME and *immediately* tries returning, does it happen?
|
Mark M. |
or will it only happen if the user is gone for a bit?
|
yuku |
Wait, let me try.
|
Oct 20 | 7:45 PM |
yuku |
It happens immediately
|
Mark M. |
hmmmm
|
Mark M. |
I haven't poked in all the dark and dusty corners of Android's tasks system
|
Mark M. |
my thought was that perhaps this was only occurring if your process was terminated
|
Mark M. |
and so Android is restarting the process and its task based on the Intent that was used to create the task in the first place
|
Mark M. |
however, if it happens immediately, you would think your process would still be around
|
Mark M. |
have you used logging or breakpoints or anything
to determine which of your activities are getting control when the user
comes back to the task?
|
yuku |
To me, it looks like when the task switcher sends
an Intent to activate my app, the Intent that is received by my app is
still the one sent by the notification
|
Mark M. |
agreed
|
yuku |
but I need to confirm that.. let me try that for a minute
|
Mark M. |
and I know that the recent tasks list is tied somewhat to that Intent
|
Mark M. |
however, I thought it was only if the process was gone
|
Mark M. |
that being said, as I said, I haven't tried all the permutations of this stuff
|
Mark M. |
which is one of the reasons there's no chapter on it in the books :-)
|
yuku |
Haha, yeah. this tasks thing is super confusing
|
yuku |
Hmm well, my root activity gets onNewIntent called
|
yuku |
when I switch back to my app using the task switcher
|
Oct 20 | 7:50 PM |
Mark M. |
are you firing off the startActivity() for A in onResume() or something?
|
yuku |
No.
|
Mark M. |
then where in root are you starting up A?
|
yuku | |
yuku | |
Mark M. |
ah, OK
|
yuku |
then A is started inside handleNotificationIntent
|
yuku |
whether A is started inside handleNotificationIntent, depends on the small extra on the intent itself.
|
Mark M. |
out of curiosity, what version of Android are you trying this on?
|
yuku |
2.3.something
|
yuku |
2.3.3
|
Oct 20 | 7:55 PM |
yuku |
by the way, the root activity has android:launchMode="singleTop"
|
yuku |
View paste
|
Mark M. |
the singleTop may not be helping your cause
|
yuku |
I put PendingIntent.FLAG_UPDATE_CURRENT, because
if I don't put that, the root activity doesn't get the extras I put on
the intent.
|
Mark M. |
yes, FLAG_UPDATE_CURRENT is typically needed if you are using extras
|
Mark M. |
you might run a test with removing singleTop and see what the behavior is
|
Mark M. |
beyond that, I'm not completely sure why you are seeing this behavior
|
yuku |
OK.. trying.
|
Mark M. | |
Oct 20 | 8:00 PM |
yuku |
Removing the singleTop doesn't solve it
|
yuku |
Thanks for the link. Reading it
|
Mark M. |
if I had to guess, the FLAG_ACTIVITY_NEW_TASK may have something to do with it
|
Mark M. |
I don't know how you can work around matters
|
Mark M. |
but the link suggests that you can at least detect when this condition occurs
|
yuku |
Hey it works!
|
yuku |
yeah.
|
Mark M. |
um, what works?
|
Oct 20 | 8:05 PM |
yuku |
It works by removing the FLAG_ACTIVITY_NEW_TASK.
|
Oct 20 | 8:05 PM |
Mark M. |
oh, right, you're starting this from a Notification
|
Mark M. |
I was thinking you were starting it straight from the C2DM message, in which case you'd have no choice but to have that flag
|
Mark M. |
since you need that for starting activities from a BroadcastReceiver
|
yuku |
Oh.. yes, true. I think I messed that up
|
Mark M. |
so that's interesting -- FLAG_ACTIVITY_NEW_TASK not only affects initial launch, but the recent-tasks list as well
|
yuku |
seems so.. if i'm not wrong, what recent-tasks screen does is nothing more than doing startActivity
|
yuku |
with some flags applied
|
Mark M. |
pretty much
|
Mark M. |
you can find out the Intents that are used via ActivityManager and getRecentTasks()
|
Mark M. |
I had a blog post about that a while ago,
particularly noting that anything you include in a startActivity()
Intent, if it winds up in that list, is visible to all applications on
the device
|
Mark M. | |
yuku |
Oh, yah, I read that one
|
Mark M. |
they at least add FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY, and perhaps more
|
yuku |
Thanks for that!
|
Mark M. |
actually, it looks like that's all they add, at least through Gingerbread
|
yuku |
Since no one else is here today.. is another question OK?
|
Mark M. |
oh, go right ahead
|
Oct 20 | 8:10 PM |
yuku |
I'm building custom widgets that consists of multiple child widgets.
|
yuku |
So let's say I'm creating UserView that extends from LinearLayout that contains 2 TextViews.
|
yuku |
so I begin writing the class
|
yuku |
public class UserView extends LinearLayout {
|
yuku |
public UserVIew(Context context, AttributeSet attrs) { super(context, attrs);
|
yuku |
LayoutInflater.from(getContext()).inflate(R.layout.my_layout_file, this, true);
|
yuku |
}}
|
yuku |
And my_layout_file.xml contains
|
yuku |
<LinearLayout>
|
yuku |
<TextView .../>
|
yuku |
<TextView .../>
|
yuku |
</LinearLayout>
|
yuku |
I thought that's the most correct way, but when I see the layout tree, I realized that
|
yuku |
the UserView has one child, which is a LinearLayout, and that LinearLayout has 2 TextView s
|
Mark M. |
correct
|
yuku |
What I actually want is the UserView has 2 TextView s
|
Mark M. |
you probably want <merge> as the root instead of <LinearLayout>
|
yuku |
what should I do?
|
yuku |
oh.
|
Mark M. | |
Mark M. |
in this case, ColorMixer is a RelativeLayout, but the same thing holds
|
Oct 20 | 8:15 PM |
Mark M. |
this should be covered in the Custom Views chapter of the Advanced Android book
|
Mark M. |
if I didn't forget
|
yuku |
OK, let me try it for a minute
|
yuku |
Oh, yeah, that works!
|
yuku |
I heard about <merge> before but I never understand the use of it
|
yuku |
thanks, again!
|
Mark M. |
it can also be helpful in conjunction with <include>
|
Mark M. |
layout A uses <include> to add in layout B
|
Mark M. |
but layout B logically is just a bunch of widgets with no specific root
|
Mark M. |
so you use <merge> to satisfy the XML
|
yuku |
understood.
|
Oct 20 | 8:20 PM |
yuku |
no wonder I was seeing too many nested views when using include.
|
yuku |
that's all for today, thanks and see you next time :D
|
Mark M. |
ok, have a pleasant day!
|
Oct 20 | 8:30 PM |
yuku | has left the room |
Mark M. | turned off guest access |