• 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

Multiple Instances of Activity

 
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 am trying to show the user information on Incoming Call screen, whenever there is an Incoming Call. So i have a Broadcast Receiver listening to Incoming calls, which starts the Intent Service, which subsequently starts an Activity (with Theme Dialog) .

Now Whenever there is an Incoming Call , My Activity Dialog Pops Up and Shows as Intended.

Problem : When the Activity Dialog is already on the Screen and Incoming call comes, there is no new Activity Dialog with new Information. I guess that whenever there is an Instance , android does not creates the new one. So it seems like my problem is "Creating Multiple Instances of an Activity".

Please note that i am starting an Activity from an Intent Service using FLAG_NEW_TASK.

Warm Regards
 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Android does create multiple instances of the activity unless you specify the FLAG_ACTIVITY_CLEAR_TOP option. Quoting the documentation for this option.

If set, and the activity being launched is already running in the current task, then instead of launching a new instance of that activity, all of the other activities on top of it will be closed and this Intent will be delivered to the (now on top) old activity as a new Intent.



If you need to receive the new intents on this activity when the clear_top flag is set, override the onNewIntent() method.
 
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
@Deepak

Although i can receive the new Intent via overriding the onNewIntent() method, how would i end up having multiple instances of an activity dialog.

 
Deepak Bala
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sahil Rally wrote:@Deepak

Although i can receive the new Intent via overriding the onNewIntent() method, how would i end up having multiple instances of an activity dialog.



When an activity is launched, the android framework creates a stacked history of activities. This is used to allow the user to press the back button and go back to a previous activity. If you do not want this behavior use the FLAG_ACTIVITY_CLEAR_TOP option.

Using FLAG_NEW_TASK will make your activity the first on the history stack. I'm not sure that is what you want.
 
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
@ Deepak

I want stack of same activity instances . Let us name an Activity as "A".

I want my broadcast receiver to launch new activity instance A whenever there is an incoming call .

So iff there are 5 calls on my phone, i can see 5 activities i.e. Stack : A A A A A

Android documentation says that it is default behaviour but it is not actually happening.

and i am using FLAG_NEW_TASK because am starting activity from an Intent service and it is required , dont exactly know why, but without it ereor comes.
Regards
 
reply
    Bookmark Topic Watch Topic
  • New Topic