Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Prevent garbage collection for Broadcast receiver that are dynamically registered
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
frantz lohier  
View profile  
 More options Aug 15 2012, 12:34 pm
From: frantz lohier <floh...@gmail.com>
Date: Wed, 15 Aug 2012 09:34:16 -0700
Local: Wed, Aug 15 2012 12:34 pm
Subject: Prevent garbage collection for Broadcast receiver that are dynamically registered

Dear All,

I've developed an app  that registers a receiver in the onResume()
constructor.

This receiver need not to be deallocated as it processes intent even when
my app is not running on the foreground.

For that reason, the receiver is not deregistered by onPause().

Now, when the app goes in background mode, I get a warning that the
receiver has leaked and, since the 4.1 update, the receiver seems to be
deallocated from memory (was not the case before).

Question: is there a way to ensure that receiver are programmatically
registered at run-time are not deallocated when an app goes in background?

Thanks,


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mark Murphy  
View profile  
 More options Aug 15 2012, 12:43 pm
From: Mark Murphy <mmur...@commonsware.com>
Date: Wed, 15 Aug 2012 12:43:42 -0400
Local: Wed, Aug 15 2012 12:43 pm
Subject: Re: [android-developers] Prevent garbage collection for Broadcast receiver that are dynamically registered

On Wed, Aug 15, 2012 at 12:34 PM, frantz lohier <floh...@gmail.com> wrote:
> Question: is there a way to ensure that receiver are programmatically
> registered at run-time are not deallocated when an app goes in background?

IMHO, a better implementation would be to register the receiver in the
manifest, then use PackageManager and setComponentEnabledSetting() to
control when it should and should not receive broadcasts. IMHO, a
receiver registered via registerReceiver() from an activity should
only be used for broadcasts while the activity is in the foreground.

--
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy

_The Busy Coder's Guide to Android Development_ Version 4.0 Available!


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
frantz lohier  
View profile  
 More options Aug 16 2012, 7:26 am
From: frantz lohier <floh...@gmail.com>
Date: Thu, 16 Aug 2012 04:26:36 -0700
Local: Thurs, Aug 16 2012 7:26 am
Subject: Re: [android-developers] Prevent garbage collection for Broadcast receiver that are dynamically registered

Thank you Mark - this was never very clear in any of the books I've bought
regarding Android programming or on Android website unfortunately.

My next question is as follows:

I've listed a receiver in the manifest as suggested pointing to the
following definition:

public class TESTWAKEUP extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
           Intent rerun=new Intent(context,MyApp.class);
           rerun.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
           rerun.putExtra("fromstaticreceiver", "parameter");
           context.startActivity(rerun);
        }
  }
   }

Now, for some reason, when my activity is brought back to the foreground by
the about receiver (which is triggered by a Service), it does not seem that
the extra parameter is ever receiver:

@Override
public void onCreate(Bundle savedInstanceState) //this is for MyApp
{
Intent argv=getIntent();
Bundle bundle = argv.getExtras();
String fromstaticreceiver=null;
if (bundle != null)
fromstaticreceiver = bundle.getString("fromstaticreceiver");
                Log.d("here:", "fromstaticreceiver=" + fromstaticreceiver);
//always shows null for fromstaticreceiver

My question is:does getIntent() represent the argument of the intent that
originally started the activity or does it reflect intent in the system
that are forcing an activity to come to the foreground?

Many thanks for any feedback on this front.

Rdgs,

On Wed, Aug 15, 2012 at 9:43 AM, Mark Murphy <mmur...@commonsware.com>wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mark Murphy  
View profile   Translate to Translated (View Original)
 More options Aug 16 2012, 7:50 am
From: Mark Murphy <mmur...@commonsware.com>
Date: Thu, 16 Aug 2012 07:50:56 -0400
Local: Thurs, Aug 16 2012 7:50 am
Subject: Re: [android-developers] Prevent garbage collection for Broadcast receiver that are dynamically registered

On Thu, Aug 16, 2012 at 7:26 AM, frantz lohier <floh...@gmail.com> wrote:
> Thank you Mark - this was never very clear in any of the books I've bought
> regarding Android programming or on Android website unfortunately.

Books and documentation cannot possibly cover the infinite variations
of applications and the ways that they are assembled.

> My question is:does getIntent() represent the argument of the intent that
> originally started the activity

I would phrase it as the one that originally created the activity.

> or does it reflect intent in the system that
> are forcing an activity to come to the foreground?

No. I think that you will be called with onNewIntent() in this case,
instead of onCreate(), and the Intent supplied to onNewIntent() will
be the one used by your startActivity() from the BroadcastReceiver. I
have not tried this in conjunction with a BroadcastReceiver and
FLAG_ACTIVITY_NEW_TASK -- at least not recently -- and so I am not
100% certain about onNewIntent() for your scenario.

--
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy

Android Training in NYC: http://marakana.com/training/android/


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »