• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Asynchronous message?

 
Ranch Hand
Posts: 162
1
Android Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Geeks

I was going through Android Guide wherein the following line is written



Could you please explain what exactly asynchronous in the above context means ??


Thanks and Warm Regards
 
Rancher
Posts: 43081
77
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It means that the code that launches the Intent does not block until it receives some result - it continues running without immediate feedback what happened to the newly launched Intent. That's different from making a synchronous call, where the code would wait until a result is available.
 
Sangel Kapoor
Ranch Hand
Posts: 162
1
Android Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ulf Ditmer , I got the point.

In Android, Applications run in its own process allocated by the Linux OS . Say Main activity is running in Process A, so when an Intent is fired from that Main Activity, does Android System launch one child Process to make in Asynchronous., ?

And moreover what happens in the case of startActivityForResult().
It may be the case that the calling Activity does not exist when called activity returns the result . What would happen in that case ? Does Android System creates an instance , or it blocks till the called activity returns the result (in which case it is no more synchronous call) , or crashes ?


 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Say Main activity is running in Process A, so when an Intent is fired from that Main Activity, does Android System launch one child Process to make in Asynchronous., ?


Asynchronicity hs nothing to do with whether both sides of the communication are part of the same process, or part of different processes. In Android, all parts of an application are executed within the same JVM process.

what happens in the case of startActivityForResult(). It may be the case that the calling Activity does not exist when called activity returns the result . What would happen in that case ? Does Android System creates an instance , or it blocks till the called activity returns the result (in which case it is no more synchronous call) , or crashes ?


The option of "crashing" was a joke, right? If no activity of the right kind is running to receive the result, one will be started. If one can't be started for some unforeseen reason, the process will likely be terminated.
 
Sangel Kapoor
Ranch Hand
Posts: 162
1
Android Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

The option of "crashing" was a joke, right? If no activity of the right kind is running to receive the result, one will be started. If one can't be started for some unforeseen reason, the process will likely be terminated.




The option of crashing was not a joke certainly, because in Android system there are scenarios where it happens. For instance, if we launch an implicit intent with some action and category , and if android system does not find any app that can support that intent , the app crashes. !!! :-)

Nevertheless, what i want to know is that what happens in an Activity which fires an Intent via startActovityForResult() ?

1. Does it wait for the other activity to respond back.?
2. or It may get killed till the time it get result from the called activity, and thus started again by system . If that is so then , may be i do not want my activity to execute onCreate() for that reason, how to handle that situation? Say i am loading something in onCreate() or in onResume()

:-) I hope i am able to keep my question clearly.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Isn't that the exact question I answered in sentence 2 and 3 of the part you quoted?
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sahil Rally wrote:The option of crashing was not a joke certainly, because in Android system there are scenarios where it happens. For instance, if we launch an implicit intent with some action and category , and if android system does not find any app that can support that intent , the app crashes. !!! :-)


No, if no Activity is found an ActivityNotFoundException is thrown. If you don't handle that exception, then the app crashes. Might sound nit-picky but it is important to realize that the crash was caused by you not handling the exception, not because the OS couldn't locate an Activity (i.e. you can control and prevent the crash).
 
Sangel Kapoor
Ranch Hand
Posts: 162
1
Android Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Steve

The following is a quote from Android developer site. Surely, i did not try this but i understood that it crashes from reading it.

Caution: It's possible that a user won't have any apps that handle the implicit intent you send to startActivity(). If that happens, the call will fail and your app will crash. To verify that an activity will receive the intent, call resolveActivity() on your Intent object. If the result is non-null, then there is at least one app that can handle the intent and it's safe to call startActivity(). If the result is null, you should not use the intent and, if possible, you should disable the feature that issues the intent.

 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That doesn't change that the app only crashes if the code doesn't do the right thing: re-read the part starting "To verify...".
 
Steve Luke
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Read the API for Context.startActivity() and Activity.startActivity() and all the other related methods. Here is a sample:

Context#startActivity(Intent, Bundle) wrote:This method throws ActivityNotFoundException if there was no Activity found to run the given Intent.


The app crashes because you don't handle that exception.
 
Sangel Kapoor
Ranch Hand
Posts: 162
1
Android Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Steve and Ulf for insights !!!
 
reply
    Bookmark Topic Watch Topic
  • New Topic