Mark M. | has entered the room |
Mark M. | turned on guest access |
Jun 24 | 7:25 PM |
EGHDK | has entered the room |
Mark M. |
hello, EGHDK!
|
Mark M. |
how can I help you today?
|
Jun 24 | 7:30 PM |
EGHDK |
Hey Mark, so I have a problem with one of my existing apps. My app basically has two activities. Activity A (main launcher activity) which is a login activity. Then if you log in you get taken to activivty B which is your inbox and activity A is finished(). The problem I'm seeing (and can't come up with concrete results) is that once I'm logged in, I can hit home and then hit multi tasking and open the app, and I get back to the inbox. Sometimes it seems that when I hit the home key and then open the app from the drawer or from a home screen, the app starts from the Login activity again.
|
Mark M. |
it depends on whether your process is running and how you get back to the app
|
Mark M. |
and, to some extent, how the user left the app
|
Mark M. |
tapping the launcher icon should always take you back to the launcher activity
|
EGHDK |
But I'm not waiting at all. I hit home, then multitask, then back in the app. If I hit home and then directly hit the app icon, it starts from activity A.
|
EGHDK |
So I guess it's an architectual problem.
|
Mark M. |
if "the app icon" is the launcher icon, then it should return you to Activity A
|
EGHDK |
Maybe I should have the inbox be the main launcher activity?
|
Mark M. |
not necessarily
|
Mark M. |
though that is one possibility
|
Mark M. |
more generally, you need to take into account that the user could return to any point in your app
|
Mark M. |
right now, you have 2 activities
|
Mark M. |
you could have 20
|
Mark M. |
you could have 200, though we'd look at you funny
|
Mark M. |
given the recent-tasks list, the user could come back to any of those
|
Mark M. |
and you may need them to log in again, particularly if your process had been terminated in the meantime
|
Mark M. |
so you need to decide how you are going to handle the more general case
|
Jun 24 | 7:35 PM |
Mark M. |
and how your launcher activity behaves should fall out of that
|
Mark M. |
for example, perhaps "login" isn't an activity, but a fragment that can be shown in any of your activities (e.g., a DialogFragment)
|
Mark M. |
and you pop it up if you don't have a valid session (e.g., new process, old session is too old)
|
EGHDK |
Makes sense. Well, I never want the user to go to the login activity once they have logged in.
|
EGHDK |
That makes sense.
|
EGHDK |
Okay. I think I will make the main launcher activity the inbox. And if the session has expired it will prompt for a password again.
|
EGHDK |
I have a flag on my application in my manifest, and I thought that maybe it was causing the issue. I had never noticed it before. But the flag is single instance.
|
Mark M. |
that's probably not what you want
|
EGHDK |
But I don't know why it's there. The flag is only valid for activities. So my question is why does android allow it to be there.
|
Mark M. |
since attributes can be added in various versions of Android, the tools are fairly lenient about what they allow
|
EGHDK |
gotcha
|
Jun 24 | 7:40 PM |
EGHDK |
I saw this somewhere and thought maybe it was the issue, but I couldn't find any documentation on it. "That means you are using some CLEAR_TOP or finish flag in an intent or in the manifest. Or possibly it has been > 30 minutes since the app was last launched, in which case the system will restart it automatically."
|
EGHDK |
Written by some diane hackborn
|
Mark M. |
Ms. Hackborn is one of the core Android engineers
|
Mark M. |
you'll see her in the Android Fireside Chat tomorrow at Google I|O, most likely
|
EGHDK |
Can I find that in the docs somewhere?
|
Mark M. |
find what?
|
EGHDK |
That if you wait 30 + minutes since an app was last launched it will restart it automatically.
|
Mark M. |
since I am not aware that this is how it works, I can't point you to documentation on it
|
EGHDK |
Okay. I found her say that here: https://groups.google.com/forum/#!topic/android...
|
EGHDK |
Next question...
|
Mark M. |
that is from 2009
|
Mark M. |
once you start getting that old, bear in mind that Android may have changed since then, in relevant ways
|
Jun 24 | 7:45 PM |
EGHDK |
Hah. I guess you have a point... But thats why I was wondering if any dev docs had it. I'd really like to learn more about what happens when an app icon is hit, app icon is hit from the drawer, or app is launched from multi task. Thats why I ask.
|
Mark M. | |
Mark M. |
and may $DEITY have mercy on your soul
|
Mark M. |
eventually, I will add a chapter on this
|
Mark M. |
I dread writing it
|
EGHDK |
Hahah.
|
EGHDK |
Is there any way for one app to have two active task stacks?
|
Mark M. |
um, that depends on your definition of "app" and "have"
|
Mark M. |
an app's activities can be in more than one task
|
EGHDK |
I guess its not important.
|
EGHDK |
Okay next question. I have an activity in my app that accepts images from the gallery. I want to accept images from applications by using an intent filter. So that after you take a picture you can press share and share it with my app.
|
Jun 24 | 7:50 PM |
EGHDK |
Are there any security risks involved in this?
|
Mark M. |
well, the images might be NSFW
|
Mark M. |
beyond that, it depends on what you're trying to do with the image
|
EGHDK |
Lets say I want to only take images, but somewhere somehow could put something malicious in it? idk I'm just trying to think of potential risks.
|
Mark M. |
somebody could give you a bogus image
|
Mark M. |
but, again, whether or not that is a "security risk" depends on what you are doing with the image
|
Mark M. |
an activity that responds to ACTION_SEND by doing nothing is not at risk
|
EGHDK |
Yeah makes sense.
|
EGHDK |
Okay next question. Remember last week I asked you why making a progress dialog then calling show, then putting a thread.sleep, waits for the sleep time, then shows the progress dialog, when in my head it should do everything in the order in which it is called. Well you said that the dialog.show() is a scheduled method. Then I asked if there is any way of knowing that a method doesn't happen and you said no.
|
Jun 24 | 7:55 PM |
EGHDK |
Is there really no way to tell that a method is scheduled?
|
EGHDK |
Because I think startActivity and finish seem like they are scheduled also.
|
Mark M. |
they are
|
EGHDK |
But I'm not sure if theres a sure fire way to test it.
|
Mark M. |
put a SystemClock.sleep(5000) immediately after one
|
Mark M. |
and, when your app freezes, and the work has not been done, you know that it only put the request on the work queue for the main application thread
|
Mark M. |
that's not a great test, for a variety of reasons, but it gets the point across
|
EGHDK |
Got it.
|
EGHDK |
Any difference between SystemClock.sleep and thread.sleep?
|
Mark M. |
Thread.sleep() throws an InterruptedException
|
Mark M. |
SystemClock.sleep() does not
|
Mark M. |
hence, it's less aggravating as a developer to use SystemClock.sleep()
|
EGHDK |
Interesting. I'm almost at the point of threading in my java book, so things like this are getting really interesting.
|
Mark M. |
rolling back to your earlier question, in general, you have no way of knowing in most programming languages, for any method/function/whatever, whether the work implied by that method/function/whatever happens immediately or not
|
Mark M. |
unless it is documented
|
Mark M. |
and in Android, such behavior is infrequently documented
|
EGHDK |
From the docs: "Three of the four component types—activities, services, and broadcast receivers—are activated by an asynchronous message called an intent." Does that sentence basically mean that they are put on the queue?
|
Mark M. |
it's more that their respective means of invocation -- such as startActivity() -- are asynchronous
|
Jun 24 | 8:00 PM |
Mark M. |
when you call startActivity(), you get control back before the activity has been started
|
Mark M. |
one could argue that the method name should have been startActivitySometimeSoonKThxBye()
|
Mark M. |
but that's a little long, even for Java
|
Mark M. |
and it's missing the obligatory Plz
|
EGHDK |
Haha. I'm starting to read that java is slow. I really need to understand the difference between java and other programming languages. But i'll get to that soon enough.
|
EGHDK |
My book makes a lot of assumptions about the reader knowing some C.
|
Jun 24 | 8:05 PM |
EGHDK |
Okay, so next question. I had a problem recently where I was concatenating a string and it was dropping a character for some reason (I don't have the program handy), but basically I solved it by using String.format vs just using +. Is there any reason for this? I know its tough without an example, but now I'm overthinking whether or not I should just use string.format everywhere instead of just concatenation.
|
Mark M. |
no, there is no reason for that
|
EGHDK |
Hmm... so I'm fine using concatenation?
|
Mark M. |
you may want to use a StringBuilder if you're doing lots of it
|
Mark M. |
String.format() is a very slow way of doing string concatenation
|
Mark M. |
but + works just fine
|
EGHDK |
Okay.
|
Jun 24 | 8:10 PM |
EGHDK |
SO this might not be the right forum for this question, but it has to do with me not fully understanding java compiled code vs something like objective c compiled code. I read a quote saying this "Swift. Because even the world's best object-oriented portable assembly language is not the right tool for some jobs." talking about Obj C. So the "best" is subjective, but does this mean that objective C, along with C gets compiled down to assembly language? Is that why its so fast compared to Java (apparently)?
|
Mark M. |
I have never written in Objective-C
|
Mark M. |
my guess is that it compiles to machine code at build time, as do C/C++
|
Mark M. |
historically, Java has been an interpreted language, using "just-in-time compilation" (a.k.a., JIT) to convert key segments of code into machine code at runtime
|
EGHDK |
machine code = assembly? So! Isn't java not using JIT anymore in ART?
|
EGHDK |
Isn't it using Ahead of Time?
|
Mark M. |
machine code != assembly, though there is usually a 1:1 mapping between them
|
Mark M. |
the ART runtime will apply JIT-ish techniques to compile your entire app to machine code at install time
|
EGHDK |
Isn't Android* not using JIT anymore.
|
Mark M. |
at the moment, the ART runtime is used by ~0% of Android users
|
EGHDK |
That to me sound like native code then.
|
Mark M. |
it is; the question is merely when that native/machine code is generated
|
Jun 24 | 8:15 PM |
Mark M. |
for Objective-C/C/C++, it is generated on the developer's PC
|
Mark M. |
(where by "PC" I include OS X boxen)
|
Mark M. |
for code written in Java for Android, with ART, the machine code is generated on the device at install time
|
EGHDK |
Yeah. So that to me sounds awesome. It seems like you will be running 100% compiled code at runtime, and won't have to wait while the app is running.
|
Mark M. |
well, it doesn't solve all "have to wait while the app is running" issues
|
Mark M. |
things that are CPU bound will improve
|
Mark M. |
things that are I/O bound will not
|
EGHDK |
I/O so stuff like multi touch and peripherals? or i/o like file io?
|
Mark M. |
yes to all
|
Mark M. |
and network I/O
|
Mark M. |
and Bluetooth I/O
|
Mark M. |
etc.
|
Mark M. |
multitouch is less of an issue, in practical terms
|
EGHDK |
So if the app did only CPU stuff (like algorithms or something... can't really think of cpu intensive tasks), in my head this means to me that Java is now as fast as C... but I'm guessing that's sadly not the case?
|
Mark M. |
JIT compilation has generally been pretty good, though better on servers (with lots more RAM) than on phones
|
Mark M. |
a lot of "algorithms or something" would have been converted to machine code via the JIT compiler in most cases
|
Jun 24 | 8:20 PM |
Mark M. |
the ahead-of-time (AOT) compilation offered by ART ensures that *all* of it is machine code
|
Mark M. |
and it eliminates the overhead of actually doing the JIT compilation work
|
Mark M. |
so the effects will be visible, but modest, for CPU-bound code
|
Mark M. |
so, for example, your game AI logic will run a bit more efficiently
|
Mark M. |
in fact, efficiency, more than raw speed, is the rationale AFAIK
|
Mark M. |
pre-compiled machine code uses fewer CPU instructions, which means less battery consumption
|
Mark M. |
so, while the user might get a bit of a speed boost, they will also see better battery life
|
EGHDK |
So wait. because I thought I followed you up until you said "the ahead-of-time (AOT) compilation offered by ART ensures that *all* of it is machine code" But didn't you say some stuff will still need JIT like i/o?
|
Mark M. |
no
|
Mark M. |
with ART, all of the code you write in Java will be converted to machine code ahead of time
|
Mark M. |
that does not magically make the Internet faster
|
Mark M. |
so, while the AI routines of your game may be more efficient, your thread waiting on the game server is still waiting on the game server
|
Mark M. |
and all the compilers in the world won't change that
|
EGHDK |
Hmm... alright. So 100% of your code will be compiled at install with ART?
|
Mark M. |
yes
|
Mark M. |
bearing in mind that ART is an underdocumented moving target
|
Mark M. |
there's an I|O presentation on it tomorrow or Thursday; watch the YouTube video or livestream
|
Jun 24 | 8:25 PM |
EGHDK |
Okay, so I mistook what you said about i/o. I thought you meant i/o still means it will need JIT. you meant that i/o is inherintly slow because it relys on other stuff. file io depends on harddrive/memory card. network i/o depends on internet connection and so on...?
|
Mark M. |
correct
|
Mark M. |
and the "other stuff" is usually slow
|
EGHDK |
GOT IT. Thanks mark.
|
EGHDK |
Okay, so my last question. Is that I have an adapter with about 2k items.
|
EGHDK |
I am trying to filter it asynchronously, but every time I do myFilter.getFilter.filter(sequence) it hangs the UI.
|
JK | has entered the room |
EGHDK |
So I put it in an async task, then I get a crash with some looper/handler/something or other complaints.
|
EGHDK |
.filter(sequence) in documentation says its async.
|
Mark M. |
JK: the chat is nearly over
|
JK |
Hello everyone
|
Mark M. |
JK: if you have an insanely quick question, go ahead
|
Mark M. |
EGHDK: I have not tried using Filter on a large data set
|
JK |
oh goodness, I from Singapore so the time wasn't good
|
JK |
it is 8.30am and I just arrive in office
|
Mark M. |
JK: sorry, my chat hours are not ideal for Singapore
|
JK |
I understand. Just have a quick question..
|
EGHDK |
So I thought .getFilter was the culprit. But I put that in an async, but still no luck. Get the same looper crash complaint. It runs fine, but UI hangs. Any quick debug tips that you'd do?
|
JK |
referring to your blog http://commonsware.com/blog/2010/09/29/another-...
|
Jun 24 | 8:30 PM |
JK |
about bindservice and rotation. i was wondering whether is it possible to have the bindservice from Activity A to Activity B
|
Mark M. |
EGHDK: I don't have any quick suggestions, other than to use Traceview and determine where your problem really lies
|
Mark M. |
JK: no, sorry, a service binding is unique to an activity
|
EGHDK |
Got it. Will look into that. Thanks. Till next meeting. Have a happy I/O tomorrow!
|
JK |
but getApplicationContext().bindservice bind to the application context isn't it?
|
JK |
not to the activity so pardon me as I am newbie
|
Mark M. |
JK: yes, but your ServiceConnection is usually tied to the activity
|
JK |
isn't it posssible to pass the bindservice by bundle..
|
Mark M. |
I rather doubt it
|
Mark M. |
and if you are "newbie", I would not recommend bound services
|
JK |
oh ok. if that is the case, thanks for the information
|
Mark M. |
OK, that is a wrap for today's chat
|
Mark M. |
the transcript will be posted to http://commonsware.com/office-hours/ shortly
|
JK |
thank you and have a good evening
|
JK |
bye
|
Mark M. |
the next chat is Friday at 10am US Eastern Time
|
Mark M. |
have a pleasant day!
|
EGHDK | has left the room |
JK | has left the room |
Mark M. | turned off guest access |