[android-developers] Re: Broadcast receiver in foreground activity - not reliable?

2013-03-12 Thread Piren
Not sure what's going on then... i suggest you add some logging to your 
activity and receiver and try to see what goes wrong... i'm guessing that 
when the app is in the foreground a different intent is being sent (maybe 
because they exit the car mode differently). Not familiar with these 
situations,.sorry :)

On Tuesday, March 12, 2013 2:37:35 AM UTC+2, lbendlin wrote:
>
> It is registered in onCreate and unregistered in onDestroy of that 
> activity.
>
> On Monday, March 11, 2013 4:02:36 AM UTC-4, Piren wrote:
>>
>> in what lifecycle events do you register/unregister this receiver?
>>
>>
>>
>> On Sunday, March 10, 2013 4:25:37 PM UTC+2, lbendlin wrote:
>>>
>>> I got a user reporting that our app does correctly terminate when the 
>>> user's device exits car mode, but only when the activity that contains the 
>>> receiver is not active. If the activity is in the foreground then more 
>>> often than not our app does not terminate.
>>>
>>> The activity is defined as
>>>
>>>>>
>>> android:name=".MainScreen"
>>>
>>> android:alwaysRetainTaskState="true"
>>>
>>> android:configChanges="orientation"
>>>
>>> android:label="@string/app_name"
>>>
>>> android:launchMode="singleTask" >
>>>
>>> 
>>>
>>> 
>>>
>>> >> "android.intent.category.LAUNCHER" />
>>>
>>> >> "android.intent.category.CAR_DOCK" />
>>>
>>> >> "android.intent.category.CAR_MODE" />
>>>
>>> 
>>>
>>> 
>>>
>>>
>>>
>>> The receiver is very simple
>>>
>>>
>>> *private* BroadcastReceiver undockReceiver = *new* BroadcastReceiver() {
>>>
>>> @Override
>>>
>>> *public* *void* onReceive(Context context, Intent intent) {
>>>
>>> *if* (intent.getAction().equals("android.app.action.EXIT_CAR_MODE")) 
>>> {
>>>
>>>  finish();
>>>
>>> }
>>>
>>> }
>>>
>>> };
>>>
>>>
>>> Is there a reason that the receiver does not work reliably?  Is it bad 
>>> practice to put a receiver inside the main activity? or does it have to do 
>>> with the activity flags?
>>>
>>>

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to android-developers+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[android-developers] Re: Broadcast receiver in foreground activity - not reliable?

2013-03-11 Thread lbendlin
It is registered in onCreate and unregistered in onDestroy of that activity.

On Monday, March 11, 2013 4:02:36 AM UTC-4, Piren wrote:
>
> in what lifecycle events do you register/unregister this receiver?
>
>
>
> On Sunday, March 10, 2013 4:25:37 PM UTC+2, lbendlin wrote:
>>
>> I got a user reporting that our app does correctly terminate when the 
>> user's device exits car mode, but only when the activity that contains the 
>> receiver is not active. If the activity is in the foreground then more 
>> often than not our app does not terminate.
>>
>> The activity is defined as
>>
>>>
>> android:name=".MainScreen"
>>
>> android:alwaysRetainTaskState="true"
>>
>> android:configChanges="orientation"
>>
>> android:label="@string/app_name"
>>
>> android:launchMode="singleTask" >
>>
>> 
>>
>> 
>>
>> > />
>>
>> > />
>>
>> > />
>>
>> 
>>
>> 
>>
>>
>>
>> The receiver is very simple
>>
>>
>> *private* BroadcastReceiver undockReceiver = *new* BroadcastReceiver() {
>>
>> @Override
>>
>> *public* *void* onReceive(Context context, Intent intent) {
>>
>> *if* (intent.getAction().equals("android.app.action.EXIT_CAR_MODE")) 
>> {
>>
>>  finish();
>>
>> }
>>
>> }
>>
>> };
>>
>>
>> Is there a reason that the receiver does not work reliably?  Is it bad 
>> practice to put a receiver inside the main activity? or does it have to do 
>> with the activity flags?
>>
>>

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to android-developers+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[android-developers] Re: Broadcast receiver in foreground activity - not reliable?

2013-03-11 Thread Piren
in what lifecycle events do you register/unregister this receiver?



On Sunday, March 10, 2013 4:25:37 PM UTC+2, lbendlin wrote:
>
> I got a user reporting that our app does correctly terminate when the 
> user's device exits car mode, but only when the activity that contains the 
> receiver is not active. If the activity is in the foreground then more 
> often than not our app does not terminate.
>
> The activity is defined as
>
>
> android:name=".MainScreen"
>
> android:alwaysRetainTaskState="true"
>
> android:configChanges="orientation"
>
> android:label="@string/app_name"
>
> android:launchMode="singleTask" >
>
> 
>
> 
>
>  />
>
>  />
>
>  />
>
> 
>
> 
>
>
>
> The receiver is very simple
>
>
> *private* BroadcastReceiver undockReceiver = *new* BroadcastReceiver() {
>
> @Override
>
> *public* *void* onReceive(Context context, Intent intent) {
>
> *if* (intent.getAction().equals("android.app.action.EXIT_CAR_MODE")) {
>
>  finish();
>
> }
>
> }
>
> };
>
>
> Is there a reason that the receiver does not work reliably?  Is it bad 
> practice to put a receiver inside the main activity? or does it have to do 
> with the activity flags?
>
>

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to android-developers+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[android-developers] Re: Broadcast receiver not working in ICS

2012-07-13 Thread Johan Appelgren
To request a permission you have to use the uses-permission element. 

http://developer.android.com/guide/topics/manifest/uses-permission-element.html
 

What you have done is require that the sender of the BOOT_COMPLETED intent 
has been granted the RECEIVE_BOOT_COMPLETED permission. Don't think that is 
what you intended. 

http://developer.android.com/guide/topics/manifest/receiver-element.html#prmsn
 

On Thursday, July 12, 2012 11:02:42 AM UTC+2, Live Happy wrote:
>
> i have  a service with separate processes in  my application run from 
> Broadcast receive after boot completed i tested the code in android 2.3.3 
> and all is work fine but when i tested on ICS 4.0.3 even the processes 
> exist in the applications runing  but its not write the throw  logs  in the 
> receiver class and n the service class  is there any help with that please 
>
>   android:process=":my_process" 
> android:label="MyServices">
> 
>android:name = ".Services.MyServices">
>
>
>
>   android:enabled="true"
>  
> android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
> 
>  android:name="android.intent.action.BOOT_COMPLETED"/>
>/>
> 
> 
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: Broadcast receiver not working in ICS

2012-07-13 Thread Johan Appelgren
To request a permission you have to use the uses-permission element. 

http://developer.android.com/guide/topics/manifest/uses-permission-element.html
 

What you have done is require that the sender of the BOOT_COMPLETED intent 
has been granted the RECEIVE_BOOT_COMPLETED permission. Don't think that is 
what you intended. 

http://developer.android.com/guide/topics/manifest/receiver-element.html#prmsn
 

On Thursday, July 12, 2012 11:02:42 AM UTC+2, Live Happy wrote:
>
> i have  a service with separate processes in  my application run from 
> Broadcast receive after boot completed i tested the code in android 2.3.3 
> and all is work fine but when i tested on ICS 4.0.3 even the processes 
> exist in the applications runing  but its not write the throw  logs  in the 
> receiver class and n the service class  is there any help with that please 
>
>   android:process=":my_process" 
> android:label="MyServices">
> 
>android:name = ".Services.MyServices">
>
>
>
>   android:enabled="true"
>  
> android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
> 
>  android:name="android.intent.action.BOOT_COMPLETED"/>
>/>
> 
> 
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: Broadcast receiver starts a new thread, do I need to kill it?

2012-07-04 Thread G. Blake Meike
If there's a reason to do this asynchronously, you should do it with an 
AsyncTask.  On the other hand, I'm with Justin wondering why you want it 
done asynchronously, at all...

G. Blake Meike
Marakana

The second edition of Programming Android is now on-line:
http://shop.oreilly.com/product/0636920023005.do


On Friday, June 22, 2012 11:29:04 AM UTC-7, Justin Robinson wrote:
>
> Every 30 seconds my broadcast receiver starts a service thread like this:
>
> Thread t = new Thread(){
> @Override
> public void run(){
> Intent intent = new Intent(context, AlarmService.class);
> context.startService(intent);
> }
> };
> t.start();
>
> Is this thread killed after 10 secs along with the broadcast receiver or 
> do I need to kill it manually?
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: Broadcast receiver receive empty extras

2012-04-19 Thread viktor
I copy My trouble from another thread:

I had a simple app that has Service and Application.
Application starts Service by Action with Intent.

The Service received Intent with onStartCommand and handle some action
by
key that is in Intent.

Sometime Service receives empty Intent.

public void sendRequest(int type, Intent data) {
  Intent i = new Intent(getLocalServiceAction());
  i =
i.putExtras(data).putExtra(LocalApiService.INTENT_NAME_REQUEST_ID,
type);
  startService(i);
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
  if (intent != null) {
onHandleIntent(intent);
  }
  return START_REDELIVER_INTENT;
}

protected void onHandleIntent(Intent intent) {
  prepareDataFromReceiver(intent);
}
public void prepareDataFromReceiver(Intent extras) {
  int type =
extras.getIntExtra(LocalApiService.INTENT_NAME_REQUEST_ID, -1);
  //Sometime type doesn't in Intent
  ...
}


I have fixed my problem with service manifest
parameter( android:process=":MyService");


On 19 Кві, 14:18, TreKing  wrote:
> On Thu, Apr 19, 2012 at 3:04 AM, viktor  wrote:
> > Didn't fix my problem, after a long time I still receive an empty Extras,
> > it is on 2.1.
>
> You need to explain your problem better. Like what is "a long time". What
> is different between these times?
>
> --- 
> --
> TreKing  - Chicago
> transit tracking app for Android-powered devices

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] Re: Broadcast receiver receive empty extras

2012-04-19 Thread TreKing
On Thu, Apr 19, 2012 at 3:04 AM, viktor  wrote:

> Didn't fix my problem, after a long time I still receive an empty Extras,
> it is on 2.1.
>

You need to explain your problem better. Like what is "a long time". What
is different between these times?

-
TreKing  - Chicago
transit tracking app for Android-powered devices

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: Broadcast receiver receive empty extras

2012-04-19 Thread viktor
Didn't fix my problem, after a long time I still receive an empty
Extras, it is on 2.1.

On 18 Кві, 22:00, TreKing  wrote:
> On Wed, Apr 18, 2012 at 1:51 PM, viktor  wrote:
> > Yes, I agree with but sometimes an Extras comes with Bundle[{}];
>
> I don't know what that means.
>
> > You also can take a look to this thread:
> >http://groups.google.com/group/android-developers/browse_thread/threa...
>
> Your link is bad.
>
> --- 
> --
> TreKing  - Chicago
> transit tracking app for Android-powered devices

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] Re: Broadcast receiver receive empty extras

2012-04-18 Thread TreKing
On Wed, Apr 18, 2012 at 1:51 PM, viktor  wrote:

> Yes, I agree with but sometimes an Extras comes with Bundle[{}];
>

I don't know what that means.


> You also can take a look to this thread:
> http://groups.google.com/group/android-developers/browse_thread/threa...
>

Your link is bad.

-
TreKing  - Chicago
transit tracking app for Android-powered devices

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] Re: Broadcast receiver receive empty extras

2012-04-18 Thread Justin Anderson
>
> Originally, you were putting the int in the bundle, then the bundle in the
> intent. On receipt, you were trying to get the data from the intent.

Wow... can't believe I missed that.  Woops!

Thanks,
Justin Anderson
MagouyaWare Developer
http://sites.google.com/site/magouyaware


On Wed, Apr 18, 2012 at 12:36 PM, TreKing  wrote:

> Originally, you were putting the int in the bundle, then the bundle in the
> intent. On receipt, you were trying to get the data from the intent.
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: Broadcast receiver receive empty extras

2012-04-18 Thread viktor
Yes, I agree with but sometimes an Extras comes with Bundle[{}];

You also can take a look to this thread:
http://groups.google.com/group/android-developers/browse_thread/threa...


On 18 Кві, 21:36, TreKing  wrote:
> On Wed, Apr 18, 2012 at 1:24 PM, viktor  wrote:
> > Seems works with i.putExtra(LocalApiService.INTENT_EXTRA, data),
> > thanks.
>
> > What is the problem was?
>
> Originally, you were putting the int in the bundle, then the bundle in the
> intent. On receipt, you were trying to get the data from the intent.
>
> It would probably also work if you did i.getExtras().getInt(...).
>
> --- 
> --
> TreKing  - Chicago
> transit tracking app for Android-powered devices

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] Re: Broadcast receiver receive empty extras

2012-04-18 Thread TreKing
On Wed, Apr 18, 2012 at 1:24 PM, viktor  wrote:

> Seems works with i.putExtra(LocalApiService.INTENT_EXTRA, data),
> thanks.
>
> What is the problem was?
>

Originally, you were putting the int in the bundle, then the bundle in the
intent. On receipt, you were trying to get the data from the intent.

It would probably also work if you did i.getExtras().getInt(...).

-
TreKing  - Chicago
transit tracking app for Android-powered devices

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: Broadcast receiver receive empty extras

2012-04-18 Thread viktor
Seems works with i.putExtra(LocalApiService.INTENT_EXTRA, data),
thanks.

What is the problem was?

On 18 Кві, 20:03, Justin Anderson  wrote:
> I don't really see anything wrong there...  Have you tried this 
> method?http://developer.android.com/reference/android/content/Intent.html#pu...
>
> Thanks,
> Justin Anderson
> MagouyaWare Developerhttp://sites.google.com/site/magouyaware
>
>
>
>
>
>
>
> On Wed, Apr 18, 2012 at 10:49 AM, viktor  wrote:
> > startId

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] Re: Broadcast receiver receive empty extras

2012-04-18 Thread Justin Anderson
I don't really see anything wrong there...  Have you tried this method?
http://developer.android.com/reference/android/content/Intent.html#putExtra%28java.lang.String,%20android.os.Bundle%29

Thanks,
Justin Anderson
MagouyaWare Developer
http://sites.google.com/site/magouyaware


On Wed, Apr 18, 2012 at 10:49 AM, viktor  wrote:

> startId

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: Broadcast receiver receive empty extras

2012-04-18 Thread viktor
Application:

public void sendRequest(int type, Bundle data) {
Intent i = new Intent(getLocalServiceAction());
data.putInt(LocalApiService.INTENT_NAME_REQUEST_ID, type);
i.putExtras(data);
ALLogger.log(Log.DEBUG, TAG, "sendRequest, type: " + type + ",
intent: " + i + ", data: " + data);
startService(i);
}

Service:

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if (intent != null) {
onHandleIntent(intent);
}
return START_STICKY;
}

protected void onHandleIntent(Intent intent) {
int type =
intent.getIntExtra(LocalApiService.INTENT_NAME_REQUEST_ID, -1);
prepareDataFromReceiver(type, intent.getExtras());
}



On 18 Кві, 19:38, Justin Anderson  wrote:
> > Sorry, it is problem with Service.
> > this one:
> >http://groups.google.com/group/android-developers/browse_thread/threa...
>
> Sorry, but a link to an identical problem posted by you doesn't prove this
> is a problem with the Service class..
>
> What does your code look like when you start the service?  And what does
> your service code look like where you try to get the Intent extras?
>
> Thanks,
> Justin Anderson
> MagouyaWare Developerhttp://sites.google.com/site/magouyaware
>
>
>
>
>
>
>
> On Wed, Apr 18, 2012 at 9:49 AM, viktor  wrote:
> > Sorry, it is problem with Service.
>
> > this one:
> >http://groups.google.com/group/android-developers/browse_thread/threa...
>
> > On 18 Кві, 18:14, Justin Anderson  wrote:
> > > What action are you receiving?  Is it your own custom action or one
> > defined
> > > by Android?  If it is a custom action then you would need to figure out
> > why
> > > you are sending the broadcast without extras.
>
> > > If it is defined by Android, then it may be some other application that
> > > sends the broadcast, in which case you could probably ignore it if there
> > > are no extras.
>
> > > Thanks,
> > > Justin Anderson
> > > MagouyaWare Developerhttp://sites.google.com/site/magouyaware
>
> > > On Wed, Apr 18, 2012 at 3:00 AM, viktor 
> > wrote:
> > > > Hi,
>
> > > > I had a simple app that has Service and Application.
>
> > > > Service sends broadcasts by Action with extras.
>
> > > > Application receive this broadcast and handle some action by key that
> > > > is in extras.
>
> > > > Sometime application receive empty extras, so if I get
> > > > Intent.getExtras(), the Bundle will be empty;
>
> > > > Any workarounds?
>
> > > > --
> > > > You received this message because you are subscribed to the Google
> > > > Groups "Android Developers" group.
> > > > To post to this group, send email to
> > android-developers@googlegroups.com
> > > > To unsubscribe from this group, send email to
> > > > android-developers+unsubscr...@googlegroups.com
> > > > For more options, visit this group at
> > > >http://groups.google.com/group/android-developers?hl=en
>
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Android Developers" group.
> > To post to this group, send email to android-developers@googlegroups.com
> > To unsubscribe from this group, send email to
> > android-developers+unsubscr...@googlegroups.com
> > For more options, visit this group at
> >http://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Broadcast receiver receive empty extras

2012-04-18 Thread viktor
Sorry, it is problem with Service.

this one: 
http://groups.google.com/group/android-developers/browse_thread/thread/f5c1f6af2914cde6

On 18 Кві, 18:14, Justin Anderson  wrote:
> What action are you receiving?  Is it your own custom action or one defined
> by Android?  If it is a custom action then you would need to figure out why
> you are sending the broadcast without extras.
>
> If it is defined by Android, then it may be some other application that
> sends the broadcast, in which case you could probably ignore it if there
> are no extras.
>
> Thanks,
> Justin Anderson
> MagouyaWare Developerhttp://sites.google.com/site/magouyaware
>
>
>
>
>
>
>
> On Wed, Apr 18, 2012 at 3:00 AM, viktor  wrote:
> > Hi,
>
> > I had a simple app that has Service and Application.
>
> > Service sends broadcasts by Action with extras.
>
> > Application receive this broadcast and handle some action by key that
> > is in extras.
>
> > Sometime application receive empty extras, so if I get
> > Intent.getExtras(), the Bundle will be empty;
>
> > Any workarounds?
>
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Android Developers" group.
> > To post to this group, send email to android-developers@googlegroups.com
> > To unsubscribe from this group, send email to
> > android-developers+unsubscr...@googlegroups.com
> > For more options, visit this group at
> >http://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Broadcast receiver won't receive camera event!

2012-03-28 Thread Alik Elzin
The action "com.android.camera.NEW_PICTURE" is not documented.
Why should it work on different devices?

On Saturday, January 1, 2011 6:46:54 PM UTC+2, androidman wrote:
>
> Hi, I'm trying to make an app that detects when a user takes a photo. 
> I set up a broadcast receiver class and registered it in the manifest 
> file by: 
>
>  
>
>  
>
>   
>  
> No matter what I try to do the program won't receive the broadcast. 
> Here is my receiver class: 
>
> public class photoReceiver extends BroadcastReceiver { 
>   private static final String TAG = "photoReceiver"; 
>
> @Override 
> public void onReceive(Context context, Intent intent) { 
> CharSequence text = "caught it"; 
> int duration = Toast.LENGTH_LONG; 
> Log.d(TAG, "Received new photo"); 
>
> Toast toast = Toast.makeText(context, text, duration); 
> toast.show(); 
>  } 
> } 
> If I remove the mimeType line in the manifest and in my activity I 
> send my own broadcast using 
>
> Intent intent = new Intent("com.android.camera.NEW_PICTURE"); 
> sendBroadcast(intent); 
> then I successfully receive the broadcast and can see the log and 
> toast window. Am I approaching this the right way? Is there any thing 
> that I need to add? Thanks in advance for the help! 
>
> Also, the NEW_PICTURE is defined in the camera source, see a thread 
> here: stackoverflow.com/questions/3015448/…, when a picture is taken 
> it calls sendBroadcast(new Intent("com.android.camera.NEW_PICTURE", 
> mLastContentUri));

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] Re: Broadcast receiver execution.

2012-03-26 Thread Mark Murphy
On Mon, Mar 26, 2012 at 5:00 AM, Put_tiMe  wrote:
> Are you sure about the system intents being delivered not in the sequence
> they were generated?

AFAIK, there is nothing in the documentation that guarantees the
delivery order for events like this. Hence, it is risky to assume a
particular order.

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

Android App Developer Books: http://commonsware.com/books

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Broadcast receiver execution.

2012-03-26 Thread Put_tiMe
Hmm, that is actually quite surprising to me. Especially if I want to do 
something on screen-on and off.
 
So in the above case, if I get the intents in this order Off, On, On, Off   
instead of the right sequence Off, On, Off, On, then all my logic will go 
horribly wrong.
 
 
Are you sure about the system intents being delivered not in the sequence 
they were generated?
 
 

On Monday, March 26, 2012 1:16:51 PM UTC+5:30, Ali Chousein wrote:

> For anything which works asynchronously (BroadcastReceivers work 
> asynchronously) I wouldn't make any assumptions that you are going to 
> receive messages in order. 
>
> --​--- 
> Ali Chousein 
> http://socialnav.blogspot.com | http://twitter.com/socialnav1 
> http://weatherbuddy.blogspot.​com  | 
> http://twitter.com/weather_​buddy  
> http://www.codeproject.com/KB/​android/PayGol-Android.aspx
>  
> http://geo-filtered-assistant.​blogspot.com
>  
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: Broadcast receiver execution.

2012-03-26 Thread Ali Chousein
For anything which works asynchronously (BroadcastReceivers work
asynchronously) I wouldn't make any assumptions that you are going to
receive messages in order.

-
Ali Chousein
http://socialnav.blogspot.com | http://twitter.com/socialnav1
http://weatherbuddy.blogspot.com | http://twitter.com/weather_buddy
http://www.codeproject.com/KB/android/PayGol-Android.aspx
http://geo-filtered-assistant.blogspot.com

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Broadcast Receiver inside a library project

2012-03-13 Thread Brett
Thanks Mark, that's what I figured.

On Mar 13, 12:50 pm, Mark Murphy  wrote:
> On Tue, Mar 13, 2012 at 3:42 PM, Brett  wrote:
> > It looks like unless I declare in project B's manifest to
> > register the receiver in project A that it won't work.
>
> Correct. The hosting project always needs to declare the components.
>
> > Is there any way for a library project to independently register for a
> > receiver in it's own manifest file?
>
> Not at the present time.
>
> --
> Mark Murphy (a Commons 
> Guy)http://commonsware.com|http://github.com/commonsguyhttp://commonsware.com/blog|http://twitter.com/commonsguy
>
> Android Training...At Your Office:http://commonsware.com/training

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Broadcast Receiver issue

2012-02-23 Thread brian lee
So, just so I understand this correctly. I will need two classes, one
the broadcastreciever and the other the service. The broadcastreciever
will listen for the boot complete to start the service. The service
will then listen for the headset broadcast and pass that back to the
broadcastreciever class.

sound about right?

On Feb 23, 4:14 pm, YuviDroid  wrote:
> This post might help 
> you:http://groups.google.com/group/android-developers/browse_thread/threa...
>
>
>
>
>
>
>
>
>
> On Thu, Feb 23, 2012 at 11:09 PM, brian lee  wrote:
> > I am trying to write what I think is a very simple application just to
> > check for when the head phone is plugged in and then mute the
> > notification sounds. I am a bit confused on the broadcast receiver,
> > can I have a app that is just that class and have it listen for when
> > that action happens, do I need a service running as well?
>
> > Here is my code:
>
> > package com.blee.checkheadphone;
>
> > import android.content.BroadcastReceiver;
> > import android.content.Context;
> > import android.content.Intent;
> > import android.media.AudioManager;
> > import android.os.Bundle;
> > import android.util.Log;
>
> > public class CheckheadphoneManager extends BroadcastReceiver {
>
> >        public static final String LOG_TAG = "Checkheadphone";
>
> >        Context mContext;
> >        private AudioManager mAudioManager;
> >        private final String HEADSET_ACTION =
> > "android.intent.action.HEADSET_PLUG";
>
> >        @Override
> >        public void onReceive(Context arg0, Intent arg1) {
>
> >                mContext = arg0;
> >                Log.v(LOG_TAG, "Intent captured");
> >                String action = arg1.getAction();
>
> >                action.equalsIgnoreCase(HEADSET_ACTION);
>
> >                Bundle bundle = arg1.getExtras();
> >                int headValue = bundle.getInt("state");
>
> >                mAudioManager =
> > (AudioManager)arg0.getSystemService(Context.AUDIO_SERVICE);
>
> >                if(headValue==0){
> >                        //System.out.println("Headphone unplugged");
> >                        Log.v(LOG_TAG, "Headphone unplugged");
> >                        //mAudioManager.setSpeakerphoneOn(false);
>
> >  mAudioManager.setStreamMute(AudioManager.STREAM_NOTIFICATION,
> > false);
>
> >                }else{
> >                        //mAudioManager.setSpeakerphoneOn(true);
> >                        //System.out.println("Headphone plugged");
> >                        Log.v(LOG_TAG, "Headphone plugged");
>
> >  mAudioManager.setStreamMute(AudioManager.STREAM_NOTIFICATION,
> > true);
> >                }
>
> >        }
>
> > }
>
> > And my manifest:
>
> > 
> > http://schemas.android.com/apk/res/android";
> >      package="com.blee.checkheadphone"
> >      android:versionCode="1"
> >      android:versionName="1.0">
> >    
> >     > android:name="android.permission.MODIFY_AUDIO_SETTINGS"> > permission>
>
> >    
>
> >         > android:enabled="true"  >
> >                        
> >                                 > android:name="android.intent.action.HEADSET_PLUG" />
> >                                 > android:name="android.intent.category.DEFAULT" />
>
> >                        
> >                
>
> >    
> > 
>
> > When I watch logcat, nothing shows for my app.
> > Any help will be appreciated.
>
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Android Developers" group.
> > To post to this group, send email to android-developers@googlegroups.com
> > To unsubscribe from this group, send email to
> > android-developers+unsubscr...@googlegroups.com
> > For more options, visit this group at
> >http://groups.google.com/group/android-developers?hl=en
>
> --
> YuviDroid
> Check out Launch-X  (a widget
> to quickly access your favorite apps and 
> contacts!)http://android.yuvalsharon.net

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Broadcast receiver Activity is in foreground or stop.

2011-10-20 Thread Anieeh
Thanx Ali

 For your quick reply I have tried this in different way i.e.
i am putting one boolean variable called "isAppInFront" in Application
extended class and i am keep on updating this variable form onStart()
and onStop() method but the problem is as i have said i have many
activity so while switching one activity to another activity i.e.
activityA and acivityB, activityA starts activityB in that activityB's
onStart() method calls first and then activityA's onStop() so in that
case may variable will not hold actual states. And i think the same
Problem will have with the permanent Storage.

But i have solved this temporarily by setting "isAppInFront"
variable on onStart() method of all Activity i have and desetting that
variable only form the exit point of my app say Dashboard in on
onBackPressed() method coz it is called earlier than previous screen's
onStart method and never close your activity by saying finish() method
just call onBackPressed() in that call super.onBackPressed(), and your
activity get closed form this.

Thanks & Regards
  Animesh Sinha.

On Oct 21, 2:12 am, Ali Chousein  wrote:
> You know when onPause()-OnStop()-onDestroy() of your activities are
> called. Inside one of these methods write your state to permanent
> storage (e.g. DB, shared preferences, even plain text file, you name
> it). Later on you can read which state you are in from permanent
> storage. I don't know if there are better ways of doing this, but this
> simple approach should work.
>
> -
> Ali Chousein
> Weather-Buddyhttp://weatherbuddy.blogspot.com/|http://twitter.com/weather_buddy
> Geo-Filtered Assistanthttp://geo-filtered-assistant.blogspot.com/

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Broadcast receiver Activity is in foreground or stop.

2011-10-20 Thread Ali Chousein
You know when onPause()-OnStop()-onDestroy() of your activities are
called. Inside one of these methods write your state to permanent
storage (e.g. DB, shared preferences, even plain text file, you name
it). Later on you can read which state you are in from permanent
storage. I don't know if there are better ways of doing this, but this
simple approach should work.

-
Ali Chousein
Weather-Buddy
http://weatherbuddy.blogspot.com/ | http://twitter.com/weather_buddy
Geo-Filtered Assistant
http://geo-filtered-assistant.blogspot.com/

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] Re: Broadcast Receiver From Widget

2011-02-24 Thread Nguyen Dat
Dear all

Sorry for missing report relate with Target environment for this report,
just add item *7★Target Environment, **8★Notes*
-
Dear Henry,

This is result after investigate this problem, i was handler successful this
issue. So i collect as report to share with android developer. Hope it help

Here is result:
*1★Issue: *
Regarding limited from Widget, when try to register BroadcastReceiver via
explicit source code: (No effect when register BroadcastReceiver via
Manifest.xml)

*2★Example: *
BroadcastReceiver: ACTION_TIME_TICK message is one example:
As docs from Android had point out:
"You can not receive this through components declared in manifests, only by
exlicitly registering for it with Context.registerReceiver()." (Ref.1)

*3★Previous solution:*
Code Snippet:
context.registerReceiver(this, intentName); (1)

*4★ Exception when used 3★ solution*
When implement follow (1), it though exception:
android.content.ReceiverCallNotAllowedException:
IntentReceiver components are not allowed to register to receive
intents

★★Good news for anyone who need to register BroadcastReceiver in Widget :)
we CAN register successful BroadcastReceiver

*5★Our Solution:*
But, We can fixed this by used application context instead of Widget
context(*)
Code Snippet:
context.getApplicationContext.registerReceiver(this, intentName);

*6★References:*
http://developer.android.com/reference/android/content/Intent.html#ACTION_TIME_TICK
Regarding

*7★Target Environment:*
SDK 2.3, both on Emulator and NexusOne 2.3,
If anyone success with this solution please update our report

*8★Notes*
May be difference between Context object of widget and application, but i
still don't known exactly cause of this problem.

Please let me known if your have better solution or explain more clearly


Regards,
DatNQ



On Thu, Feb 24, 2011 at 3:06 PM, Nguyen Dat  wrote:

> Dear Henry,
>
> This is result after investigate this problem, i was handler
> successful this issue. So i collect as report to share with android
> developer. Hope it help
>
> Here is result:
> ★Issue:
> Regarding limited from Widget, when try to register BroadcastReceiver
> via explicit source code: (No effect when register BroadcastReceiver
> via Manifest.xml)
>
> ★Example:
> BroadcastReceiver: ACTION_TIME_TICK message is one example:
> As docs from Android had point out:
> "You can not receive this through components declared in manifests,
> only by exlicitly registering for it with
> Context.registerReceiver()." (Ref.1)
>
> ★Previous solution:
> Code Snippet:
> context.registerReceiver(this, intentName); (1)
>
> ★When implement follow (1), it though exception:
> android.content.ReceiverCallNotAllowedException:
> IntentReceiver components are not allowed to register to receive
> intents
>
> ★Good news for anyone who need to register BroadcastReceiver in
> Widget :)
> we CAN register successful BroadcastReceiver
>
> ★Our Solution:
> But, We can fixed this by used application context instead of Widget
> context(*)
> Code Snippet:
> context.getApplicationContext.registerReceiver(this, intentName);
>
> ★References:
>
> http://developer.android.com/reference/android/content/Intent.html#ACTION_TIME_TICK
> Regarding
>
> Regards,
> DatNQ
>
> On Dec 3 2009, 12:44 am, Dianne Hackborn  wrote:
> > Oh and please keep in mind -- app widgets were very deliberately designed
> to
> > work this way because on the vast majority of Android devices there is
> just
> > not nearly enough memory to be able to run at the same time all of the
> > widget users have placed on their home screen.  You need to take care in
> > your widget implementation that you respect this constraint -- a widget
> can
> > NOT be running all of the time, it must be very carefully designed to run
> as
> > little as possible and only when needed.
> >
> >
> >
> > On Wed, Dec 2, 2009 at 9:42 AM, Dianne Hackborn 
> wrote:
> > > You simply can not do this.  A BroadcastReceiver component only "lives"
> for
> > > the duration of the call to onReceiveIntent(); it is not allowed to use
> > > registerReceiver in it, because by the time you return from that method
> (at
> > > which point you could first receive anything from your register), the
> > > component is no longer alive, and the system could kill at any time to
> > > reclaim memory.
> >
> > > On Wed, Dec 2, 2009 at 1:04 AM, Henry S.  wrote:
> >
> > >> Hi,
> >
> > >> I am making a widget that needs a broadcast receiver, like the one in
> > >> com.example.android.apis.appwidget.ExampleBroadcastReceiver.  However,
> > >> the example defines Intent.ACTION_TIMEZONE_CHANGED in the manifest,
> > >> but there are some that do not allow this
> >
> > >> For example, Intent.ACTION_TIME_TICK says "You can not receive this
> > >> through components declared in manifests, only by exlicitly
> > >> registering for it with Context.registerReceiver(). "
> >
> > >> So I removed the manifest declarations and tried replacing the

[android-developers] Re: Broadcast Receiver From Widget

2011-02-24 Thread Nguyen Dat
Dear Henry,

This is result after investigate this problem, i was handler
successful this issue. So i collect as report to share with android
developer. Hope it help

Here is result:
★Issue:
Regarding limited from Widget, when try to register BroadcastReceiver
via explicit source code: (No effect when register BroadcastReceiver
via Manifest.xml)

★Example:
BroadcastReceiver: ACTION_TIME_TICK message is one example:
As docs from Android had point out:
"You can not receive this through components declared in manifests,
only by exlicitly registering for it with
Context.registerReceiver()." (Ref.1)

★Previous solution:
Code Snippet:
context.registerReceiver(this, intentName); (1)

★When implement follow (1), it though exception:
android.content.ReceiverCallNotAllowedException:
IntentReceiver components are not allowed to register to receive
intents

★Good news for anyone who need to register BroadcastReceiver in
Widget :)
we CAN register successful BroadcastReceiver

★Our Solution:
But, We can fixed this by used application context instead of Widget
context(*)
Code Snippet:
context.getApplicationContext.registerReceiver(this, intentName);

★References:
http://developer.android.com/reference/android/content/Intent.html#ACTION_TIME_TICK
Regarding

Regards,
DatNQ

On Dec 3 2009, 12:44 am, Dianne Hackborn  wrote:
> Oh and please keep in mind -- app widgets were very deliberately designed to
> work this way because on the vast majority of Android devices there is just
> not nearly enough memory to be able to run at the same time all of the
> widget users have placed on their home screen.  You need to take care in
> your widget implementation that you respect this constraint -- a widget can
> NOT be running all of the time, it must be very carefully designed to run as
> little as possible and only when needed.
>
>
>
> On Wed, Dec 2, 2009 at 9:42 AM, Dianne Hackborn  wrote:
> > You simply can not do this.  A BroadcastReceiver component only "lives" for
> > the duration of the call to onReceiveIntent(); it is not allowed to use
> > registerReceiver in it, because by the time you return from that method (at
> > which point you could first receive anything from your register), the
> > component is no longer alive, and the system could kill at any time to
> > reclaim memory.
>
> > On Wed, Dec 2, 2009 at 1:04 AM, Henry S.  wrote:
>
> >> Hi,
>
> >> I am making a widget that needs a broadcast receiver, like the one in
> >> com.example.android.apis.appwidget.ExampleBroadcastReceiver.  However,
> >> the example defines Intent.ACTION_TIMEZONE_CHANGED in the manifest,
> >> but there are some that do not allow this
>
> >> For example, Intent.ACTION_TIME_TICK says "You can not receive this
> >> through components declared in manifests, only by exlicitly
> >> registering for it with Context.registerReceiver(). "
>
> >> So I removed the manifest declarations and tried replacing the
> >> AppWidgetProvider.onEnabled function that was in the example with a
> >> call like the following:
> >> context.registerReceiver(myReceiver, new
> >> IntentFilter(Intent.ACTION_TIME_TICK));
>
> >> (where "myReceiver" is an instance of the receiver I want.)  However,
> >> when I try to run the code, I get the following error:
>
> >> Unable to start
> >> receiver...android.content.ReceiverCallNotAllowedException:
> >> IntentReceiver components are not allowed to register to receive
> >> intents
>
> >> Can anyone suggest a way to get this broadcast receiver working from a
> >> widget?
>
> >> Thanks,
> >> Henry
>
> >> --
> >> You received this message because you are subscribed to the Google
> >> Groups "Android Developers" group.
> >> To post to this group, send email to android-developers@googlegroups.com
> >> To unsubscribe from this group, send email to
> >> android-developers+unsubscr...@googlegroups.com
> >> For more options, visit this group at
> >>http://groups.google.com/group/android-developers?hl=en
>
> > --
> > Dianne Hackborn
> > Android framework engineer
> > hack...@android.com
>
> > Note: please don't send private questions to me, as I don't have time to
> > provide private support, and so won't reply to such e-mails.  All such
> > questions should be posted on public forums, where I and others can see and
> > answer them.
>
> --
> Dianne Hackborn
> Android framework engineer
> hack...@android.com
>
> Note: please don't send private questions to me, as I don't have time to
> provide private support, and so won't reply to such e-mails.  All such
> questions should be posted on public forums, where I and others can see and
> answer them.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: broadcast receiver priority question

2010-10-25 Thread kevindroid
anyone has any idea?

On Oct 24, 6:33 pm, kevindroid  wrote:
> the symptom: I have a broadcast receiver that listen to sms, when a
> sms is received, i call an activity to display.
>
> It works all fine if the screen is on and not locked.
>
> But when screen is locked, and as soon as i received the sms, the
> activity popup for a second then disappeared.
>
> and I use the code to unlock the screen
>
> getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
>
> getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
>                                 | 
> WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
>
> I think it might be the competitions with phone default sms program
> ( the sms default program shows a notification only). I am wondering
> is there a way to set priority to broadcast receivers or even the
> activity that receiver stared, to avoid the conflicts between multiple
> receivers. or set orders to execute one by one?
>
> I have tried to thread.sleep my receiver for a second, still not
> working. Any idea to solve the issue? help please.
>
> Thanks a lot.
>
> Kev

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: broadcast receiver issue

2010-07-23 Thread Kumar Bibek
Even if you declare the receiver in the manifest, you have to register
that receiver in each of your activities if you want to receive
specific intents. Declaring only in the manifest just ensures that
your receiver gets called, but it wont pass on that broadcast to your
Activities unless you register for those events.

-Kumar Bibek
http://tech-droid.blogspot.com

On Jul 23, 2:26 pm, Sandeep Phansekar 
wrote:
> thanks All  [?]
> @Agus : can u plz expalin me how to do that
>
> in my project there are 5 classes
> --> 4 class file extend *Activity* -- mainly they display user interaction
> screen
> --> 1 class file extends *BroadcastReceiver -- *capture the incomming call
> and display/ launch the one of the activity.
> --> if one of the Activity class Screen is open and call is come then at
> that point BroadcastReceiver* *is fail to launch the activity
>
> so how i do this ?
>
> thanks
> sandeep
>
> On Fri, Jul 23, 2010 at 1:13 PM, Agus  wrote:
> > no, just declare your receiver in the manifest.
>
> > On Fri, Jul 23, 2010 at 12:40 AM, Kumar Bibek 
> > wrote:
> > > You have to register the receivers in each of the activities.
>
> > > -Kumar Bibek
> > >http://tech-droid.blogspot.com
>
> > > On Jul 23, 11:12 am, Sandeep  wrote:
> > >> Hi All,
>
> > >> I am working on one project where i am using broadcast receiver in one
> > >> of my activity to capture the incomming call and its works fine.
> > >> when one of my other activity is open and that time if call is come
> > >> then my broadcast receiver is fail to respond.
> > >> can any one help me for this ?
> > >> or its nessesorry to declare broadcast receiver in all my activity to
> > >> do some comman task.
>
> > >> thanks & regards
> > >> sandeep
>
> > > --
> > > You received this message because you are subscribed to the Google
> > > Groups "Android Developers" group.
> > > To post to this group, send email to android-developers@googlegroups.com
> > > To unsubscribe from this group, send email to
> > > android-developers+unsubscr...@googlegroups.com
> > > For more options, visit this group at
> > >http://groups.google.com/group/android-developers?hl=en
>
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Android Developers" group.
> > To post to this group, send email to android-developers@googlegroups.com
> > To unsubscribe from this group, send email to
> > android-developers+unsubscr...@googlegroups.com
> > For more options, visit this group at
> >http://groups.google.com/group/android-developers?hl=en
>
>
>
>  330.gif
> < 1KViewDownload

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] Re: broadcast receiver issue

2010-07-23 Thread Sandeep Phansekar
thanks All  [?]
@Agus : can u plz expalin me how to do that

in my project there are 5 classes
--> 4 class file extend *Activity* -- mainly they display user interaction
screen
--> 1 class file extends *BroadcastReceiver -- *capture the incomming call
and display/ launch the one of the activity.
--> if one of the Activity class Screen is open and call is come then at
that point BroadcastReceiver* *is fail to launch the activity

so how i do this ?

thanks
sandeep




On Fri, Jul 23, 2010 at 1:13 PM, Agus  wrote:

> no, just declare your receiver in the manifest.
>
> On Fri, Jul 23, 2010 at 12:40 AM, Kumar Bibek 
> wrote:
> > You have to register the receivers in each of the activities.
> >
> > -Kumar Bibek
> > http://tech-droid.blogspot.com
> >
> > On Jul 23, 11:12 am, Sandeep  wrote:
> >> Hi All,
> >>
> >> I am working on one project where i am using broadcast receiver in one
> >> of my activity to capture the incomming call and its works fine.
> >> when one of my other activity is open and that time if call is come
> >> then my broadcast receiver is fail to respond.
> >> can any one help me for this ?
> >> or its nessesorry to declare broadcast receiver in all my activity to
> >> do some comman task.
> >>
> >> thanks & regards
> >> sandeep
> >
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Android Developers" group.
> > To post to this group, send email to android-developers@googlegroups.com
> > To unsubscribe from this group, send email to
> > android-developers+unsubscr...@googlegroups.com
> > For more options, visit this group at
> > http://groups.google.com/group/android-developers?hl=en
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en<<330.gif>>

Re: [android-developers] Re: broadcast receiver issue

2010-07-23 Thread Agus
no, just declare your receiver in the manifest.

On Fri, Jul 23, 2010 at 12:40 AM, Kumar Bibek  wrote:
> You have to register the receivers in each of the activities.
>
> -Kumar Bibek
> http://tech-droid.blogspot.com
>
> On Jul 23, 11:12 am, Sandeep  wrote:
>> Hi All,
>>
>> I am working on one project where i am using broadcast receiver in one
>> of my activity to capture the incomming call and its works fine.
>> when one of my other activity is open and that time if call is come
>> then my broadcast receiver is fail to respond.
>> can any one help me for this ?
>> or its nessesorry to declare broadcast receiver in all my activity to
>> do some comman task.
>>
>> thanks & regards
>> sandeep
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: broadcast receiver issue

2010-07-23 Thread Kumar Bibek
You have to register the receivers in each of the activities.

-Kumar Bibek
http://tech-droid.blogspot.com

On Jul 23, 11:12 am, Sandeep  wrote:
> Hi All,
>
> I am working on one project where i am using broadcast receiver in one
> of my activity to capture the incomming call and its works fine.
> when one of my other activity is open and that time if call is come
> then my broadcast receiver is fail to respond.
> can any one help me for this ?
> or its nessesorry to declare broadcast receiver in all my activity to
> do some comman task.
>
> thanks & regards
> sandeep

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Broadcast receiver, service & thread

2010-06-24 Thread Federico Paolinelli
Thanks again a lot for your replies.

On 24 Giu, 01:31, Mark Murphy  wrote:
> On Wed, Jun 23, 2010 at 7:24 PM, Federico Paolinelli  
> wrote:
> > If I understood correctly, I need to bind to the service in order to
> > provide it a listener, and then if I want to use the onProgressUpdate
> > for an AsyncTask started from the service, I should notify the
> > listener from the onProgressUpdate call. Is it correct?
>
> That is certainly one approach.
>

 I wasn't aware of the possibility to pass a listener to the service
after the bind, I thought that the bind was useful just from activity
--> service.

> > I thought that the standard way to update the ui from a service was to
> > send an Intent (but in this way I wouldn't be aware of the state of
> > the activity).
>
> That is another approach. I am not sure that I would necessarily cal
> it the "standard way", but you are certainly welcome to do that. In
> that case, the service would broadcast the Intent, and if an activity
> picks it up, great.

By "the standard way" I meant the way described in all the examples I
read (maybe I gotta read some other examples)

>
> --


Thanks again for the exhaustive and quick replies.

Federico

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] Re: Broadcast receiver, service & thread

2010-06-23 Thread Mark Murphy
On Wed, Jun 23, 2010 at 7:24 PM, Federico Paolinelli  wrote:
> If I understood correctly, I need to bind to the service in order to
> provide it a listener, and then if I want to use the onProgressUpdate
> for an AsyncTask started from the service, I should notify the
> listener from the onProgressUpdate call. Is it correct?

That is certainly one approach.

> I thought that the standard way to update the ui from a service was to
> send an Intent (but in this way I wouldn't be aware of the state of
> the activity).

That is another approach. I am not sure that I would necessarily cal
it the "standard way", but you are certainly welcome to do that. In
that case, the service would broadcast the Intent, and if an activity
picks it up, great.

-- 
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 *Advanced* Android Development_
Version 1.6 Available!

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Broadcast receiver, service & thread

2010-06-23 Thread Federico Paolinelli
First of all, many thanks for the quick reply.

On 24 Giu, 01:00, Mark Murphy  wrote:
> On Wed, Jun 23, 2010 at 6:50 PM, Federico Paolinelli  
> wrote:
> > Every single intent produces an action to be performed. Now the first
> > question: should I start a service (maybe with non_sticky option?) or
> > should I start a thread (or an async task) directly from the broadcast
> > receiver?
>
> Definitely the service. It is not safe for manifest-registered
> BroadcastReceivers to fork threads. The receiver is destroyed shortly
> after onReceive() ends, and that leaves your thread in limbo.
>

Ok, that's a good reason


> > If I start a service, should I do all the stuff in its body, or should
> > it start a thread.
>
> Ordinarily, I'd use an IntentService, which automatically does the
> "stuff" on a background thread, via onHandleIntent(). However, your
> later points start wandering away from the broadcast receiver into
> activities and services and UI updates, which means you may want to
> just use an ordinary Service that you can have the activities bind to.
>

Nice, I missed the IntentService while reading the docs.


> > I should do the heavy job in a thread if there are time consuming
> > operations, but what if the gui of my application is just an activity
> > with the options and a button to start the service. What is the point
> > in keeping the main thread busy?
>
> That is your UI today. It might not be your UI tomorrow. Also, the
> main application thread is at foreground priority, and so anything you
> do in that thread will hammer whatever is in the foreground, such as
> that real-time game that the user is trying to play.
>

Good point

> > Do I risk to be killed for not being
> > responsive?
>
> Absolutely.
>
> > I read here and there that I can update the gui from a background
> > thread. Can I do that even if it is started from a service?
>
> Yes, though that gets a bit tricky for services that are reacting
> (indirectly) to broadcast Intents.
>
> > The AsyncTask's onProgressUpdate is said to run in the application
> > main thread, but if the application is made of different activities,
> > who tells me which activity is the user looking at while the thread is
> > doing all its long work?
>
> You would have to keep track of that yourself. For example, you could
> bind to the service in onStart() and unbind in onStop(). While bound,
> register a listener with the service to be notified of any events. The
> service calls the listener when an event occurs. No listener means no
> activity to notify.
>

If I understood correctly, I need to bind to the service in order to
provide it a listener, and then if I want to use the onProgressUpdate
for an AsyncTask started from the service, I should notify the
listener from the onProgressUpdate call. Is it correct?
I thought that the standard way to update the ui from a service was to
send an Intent (but in this way I wouldn't be aware of the state of
the activity).


Thanks again for the fast reply and sorry if I keep bothering you all.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] Re: Broadcast Receiver without Activity.

2010-02-14 Thread Dianne Hackborn
Please don't keep a service running just to register a receiver...!  Publish
the receiver in your manifest, so that the system will launch your app when
needed and not have to keep it running all of the time.

On Sun, Feb 14, 2010 at 3:44 AM, askPrins  wrote:

> Rogerio,
> What do you mean by using a service instead? Should the service
> initiate the receiver, e.g. using registerreceiver() ?
>
>
> On Feb 12, 9:35 pm, Rogério de Souza Moraes 
> wrote:
> > Hi askPrins,
> >
> > you can implement this using a service class instead of an activity
> class.
> > So you don't need the UI.
> >
> > Regards,
> >
> > Rogerio
> >
> > 2010/2/12 askPrins 
> >
> > > A WAP PUSH (Broadcast)receiver basically doesn't need any UI. It is a
> > > silence application which handles the Push messages based on actions/
> > > mimetype without needing any intreaction with user,
> > > I've tried to test it in a SMS receiver by removing the Activity from
> > > the project and it stopped receiving the SMS messages.
> > > My question: Does all android applications "MUST" define a activity?
> > > Is there a way to hide it?
> >
> > > --
> > > You received this message because you are subscribed to the Google
> > > Groups "Android Developers" group.
> > > To post to this group, send email to
> android-developers@googlegroups.com
> > > To unsubscribe from this group, send email to
> > > android-developers+unsubscr...@googlegroups.com
> 
> >
> > > For more options, visit this group at
> > >http://groups.google.com/group/android-developers?hl=en
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>



-- 
Dianne Hackborn
Android framework engineer
hack...@android.com

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  All such
questions should be posted on public forums, where I and others can see and
answer them.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: Broadcast Receiver without Activity.

2010-02-14 Thread askPrins
Rogerio,
What do you mean by using a service instead? Should the service
initiate the receiver, e.g. using registerreceiver() ?


On Feb 12, 9:35 pm, Rogério de Souza Moraes 
wrote:
> Hi askPrins,
>
> you can implement this using a service class instead of an activity class.
> So you don't need the UI.
>
> Regards,
>
> Rogerio
>
> 2010/2/12 askPrins 
>
> > A WAP PUSH (Broadcast)receiver basically doesn't need any UI. It is a
> > silence application which handles the Push messages based on actions/
> > mimetype without needing any intreaction with user,
> > I've tried to test it in a SMS receiver by removing the Activity from
> > the project and it stopped receiving the SMS messages.
> > My question: Does all android applications "MUST" define a activity?
> > Is there a way to hide it?
>
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Android Developers" group.
> > To post to this group, send email to android-developers@googlegroups.com
> > To unsubscribe from this group, send email to
> > android-developers+unsubscr...@googlegroups.com
> > For more options, visit this group at
> >http://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] Re: Broadcast Receiver and Remote Service

2010-01-20 Thread Dianne Hackborn
A remote service is not the way to solve an ANR -- you are just moving the
ANR into another process (and hiding it because if that process isn't doing
UI, it can still ANR when background requests are being made of it and in
that case we just kill it rather than bothering the user).

A Service is basically to tell the system that your process would like to be
running.  It doesn't do anything magical -- it is just an object that is
instantiated to represent this "hey I'm doing something" state with the
system and perform interactions with the system around that.  It doesn't do
anything more than that.  It is created on the main thread and callbacks to
it happen there.  The same rules apply as elsewhere -- if you do some
long-running work in one of these callbacks, you will block your main thread
and ANR.

If you are fine with your process being killed if you are doing this work
and the user is no longer in one of your activities, then you actually do
not want to use a Service, because the core thing a Service is doing is
telling the system you do -not- want to be killed.

On Wed, Jan 20, 2010 at 3:41 PM, Natalie  wrote:

> Hi Dianne,
> I initially had the service as a local service, but my application was
> getting Application Not Responding messages.  Since I'll never have
> more than one application binding to my service, I think I'm just
> going to abandon the service approach and try the approach in the
> example jotobjects posted - I can't see any reason that having it as a
> service is useful, but am I missing something?
> Thanks!!
>
>
> On Jan 20, 3:32 pm, Natalie  wrote:
> > Thanks so much for the response.  But if the long loop (which updates
> > the field that needs to find its way to the activity) is in a
> > different thread from the one that processes the showMessage call,
> > won't I have to switch to doing the communication through the
> > Handler?  And at that point I'm beginning to wonder if it makes sense
> > to bother with the service or if I should just be doing the work on
> > different threads and communicating through the Handlers?  Or am I
> > missing something?  Maybe the example you posted will clear all this
> > up though, I'll look at that now.  :)
> >
> > On Jan 20, 3:24 pm, jotobjects  wrote:
> >
> >
> >
> > > Hi Natalie -
> >
> > > Not sure what you mean by service you "spawned onto its own thread".
> >
> > > In any case, it looks like the Service is going to be pretty busy in
> > > that while(1) loop so it is not too surprising that it is not
> > > available to process the showMessage call.  :)  Yes they are two
> > > different threads.  The Activity is blocking on the call to the
> > > service that is forever busy in the for loop.
> >
> > > I think you need to put that loop in a thread and then you need a
> > > different Runnable for the handler post().  Here is an example -
> >
> > >http://developer.android.com/resources/faq/commontasks.html#threading
> >
> > > Also the serviceHandler.post(myProcess) in onCreate is a duplicate.
> > > This is where you need something like startLongWhileLoop() that
> > > creates a thread instead.
> >
> > > On Jan 20, 2:49 pm, Natalie  wrote:
> >
> > > > Thanks for the response.
> > > > I'm pretty sure that's not it because I've put a debug statement
> first
> > > > off in the broadcast receiver's onReceive method and that isn't
> > > > appearing either.  It almost seems that the activity's thread just
> > > > isn't getting switched to - so far I've only tested in the emulator,
> > > > could the emulator not be switching back to the activity's thread?
> > > > I've posted the seemingly relevant chunks of code below if that
> helps.
> >
> > > > ACTIVITY ...
> > > > public class AudioProcessor extends Activity {
> > > > private AudioInterface service;
> > > > private ServiceConnection svcConn = new ServiceConnection(){
> > > > public void onServiceConnected(ComponentName
> className, IBinder
> > > > binder){
> > > > service =
> AudioInterface.Stub.asInterface(binder);
> > > > }
> > > > public void onServiceDisconnected(ComponentName
> className){
> > > > service = null;//NL = probably do more in
> onService methods
> > > > }
> > > > };
> > > > private BroadcastReceiver receiver = new BroadcastReceiver(){
> > > > public void onReceive(Context context, Intent
> intent){
> > > > Log.d("SHOWING!!!",
> "!!!");
> > > > showMessage(context, intent);
> > > > }
> > > > };
> > > > @Override
> > > > public void onCreate(Bundle savedInstanceState) {
> > > > super.onCreate(savedInstanceState);
> > > > setContentView(R.layout.main);
> > > > Intent serviceIntent = new Intent(this,
> AudioService.class);
> > > > bindService(serviceIntent, s

[android-developers] Re: Broadcast Receiver and Remote Service

2010-01-20 Thread Natalie
Thanks for this advice - I changed 3 lines and now it works - turns
out I was confused about the right way to go about starting my
background thread.  I'll probably move away from the Service
implementation now, but it's great to have it working!!
Thanks again everyone!

On Jan 20, 3:44 pm, jotobjects  wrote:
> The serviceHandler object you have there now doesn't seem to do
> anything useful.  You just need to start the loop in a thread so it
> doesn't block the event loop for the Service.  A complete redesign as
> Dianne suggests is probably better (and as you said maybe there is no
> reason for having a Service at all), but you might try to get what you
> have working first.
>
> On Jan 20, 3:32 pm, Natalie  wrote:
>
>
>
> > Thanks so much for the response.  But if the long loop (which updates
> > the field that needs to find its way to the activity) is in a
> > different thread from the one that processes the showMessage call,
> > won't I have to switch to doing the communication through the
> > Handler?  And at that point I'm beginning to wonder if it makes sense
> > to bother with the service or if I should just be doing the work on
> > different threads and communicating through the Handlers?  Or am I
> > missing something?  Maybe the example you posted will clear all this
> > up though, I'll look at that now.  :)
>
> > On Jan 20, 3:24 pm, jotobjects  wrote:
>
> > > Hi Natalie -
>
> > > Not sure what you mean by service you "spawned onto its own thread".
>
> > > In any case, it looks like the Service is going to be pretty busy in
> > > that while(1) loop so it is not too surprising that it is not
> > > available to process the showMessage call.  :)  Yes they are two
> > > different threads.  The Activity is blocking on the call to the
> > > service that is forever busy in the for loop.
>
> > > I think you need to put that loop in a thread and then you need a
> > > different Runnable for the handler post().  Here is an example -
>
> > >http://developer.android.com/resources/faq/commontasks.html#threading
>
> > > Also the serviceHandler.post(myProcess) in onCreate is a duplicate.
> > > This is where you need something like startLongWhileLoop() that
> > > creates a thread instead.
>
> > > On Jan 20, 2:49 pm, Natalie  wrote:
>
> > > > Thanks for the response.
> > > > I'm pretty sure that's not it because I've put a debug statement first
> > > > off in the broadcast receiver's onReceive method and that isn't
> > > > appearing either.  It almost seems that the activity's thread just
> > > > isn't getting switched to - so far I've only tested in the emulator,
> > > > could the emulator not be switching back to the activity's thread?
> > > > I've posted the seemingly relevant chunks of code below if that helps.
>
> > > > ACTIVITY ...
> > > > public class AudioProcessor extends Activity {
> > > >         private AudioInterface service;
> > > >         private ServiceConnection svcConn = new ServiceConnection(){
> > > >                 public void onServiceConnected(ComponentName className, 
> > > > IBinder
> > > > binder){
> > > >                         service = 
> > > > AudioInterface.Stub.asInterface(binder);
> > > >                 }
> > > >                 public void onServiceDisconnected(ComponentName 
> > > > className){
> > > >                         service = null;//NL = probably do more in 
> > > > onService methods
> > > >                 }
> > > >         };
> > > >         private BroadcastReceiver receiver = new BroadcastReceiver(){
> > > >                 public void onReceive(Context context, Intent intent){
> > > >                         Log.d("SHOWING!!!", 
> > > > "!!!");
> > > >                         showMessage(context, intent);
> > > >                 }
> > > >         };
> > > >         @Override
> > > >         public void onCreate(Bundle savedInstanceState) {
> > > >                 super.onCreate(savedInstanceState);
> > > >         setContentView(R.layout.main);
> > > >                 Intent serviceIntent = new Intent(this, 
> > > > AudioService.class);
> > > >                 bindService(serviceIntent, svcConn, BIND_AUTO_CREATE);
> > > >                 registerReceiver(receiver, new IntentFilter
> > > > (AudioService.BROADCAST_ACTION));
> > > >                 serviceIntent.setAction
> > > > ("com.linnell.audioprocessor.AudioService");
> > > >                 startService(serviceIntent);*/
> > > >         }
> > > >         public void showMessage(Context context, Intent intent){
> > > >                 Log.d("SHOWING!!!", "!!!");
> > > >                 try{
> > > >                         String message = service.showMessage();
> > > >                         new 
> > > > AlertDialog.Builder(this).setTitle("Suggestion")
> > > >                         .setMessage(message)
> > > >                         .setNeutralButton("Close", new 
> > > > DialogInterface.OnClickListener(){
> > > >                                 public voi

[android-developers] Re: Broadcast Receiver and Remote Service

2010-01-20 Thread jotobjects
You are getting ANR because the service is in an infinite loop!
Putting it in a remote service doesn't fix that.

On Jan 20, 3:41 pm, Natalie  wrote:
> Hi Dianne,
> I initially had the service as a local service, but my application was
> getting Application Not Responding messages.  Since I'll never have
> more than one application binding to my service, I think I'm just
> going to abandon the service approach and try the approach in the
> example jotobjects posted - I can't see any reason that having it as a
> service is useful, but am I missing something?
> Thanks!!
>
> On Jan 20, 3:32 pm, Natalie  wrote:
>
> > Thanks so much for the response.  But if the long loop (which updates
> > the field that needs to find its way to the activity) is in a
> > different thread from the one that processes the showMessage call,
> > won't I have to switch to doing the communication through the
> > Handler?  And at that point I'm beginning to wonder if it makes sense
> > to bother with the service or if I should just be doing the work on
> > different threads and communicating through the Handlers?  Or am I
> > missing something?  Maybe the example you posted will clear all this
> > up though, I'll look at that now.  :)
>
> > On Jan 20, 3:24 pm, jotobjects  wrote:
>
> > > Hi Natalie -
>
> > > Not sure what you mean by service you "spawned onto its own thread".
>
> > > In any case, it looks like the Service is going to be pretty busy in
> > > that while(1) loop so it is not too surprising that it is not
> > > available to process the showMessage call.  :)  Yes they are two
> > > different threads.  The Activity is blocking on the call to the
> > > service that is forever busy in the for loop.
>
> > > I think you need to put that loop in a thread and then you need a
> > > different Runnable for the handler post().  Here is an example -
>
> > >http://developer.android.com/resources/faq/commontasks.html#threading
>
> > > Also the serviceHandler.post(myProcess) in onCreate is a duplicate.
> > > This is where you need something like startLongWhileLoop() that
> > > creates a thread instead.
>
> > > On Jan 20, 2:49 pm, Natalie  wrote:
>
> > > > Thanks for the response.
> > > > I'm pretty sure that's not it because I've put a debug statement first
> > > > off in the broadcast receiver's onReceive method and that isn't
> > > > appearing either.  It almost seems that the activity's thread just
> > > > isn't getting switched to - so far I've only tested in the emulator,
> > > > could the emulator not be switching back to the activity's thread?
> > > > I've posted the seemingly relevant chunks of code below if that helps.
>
> > > > ACTIVITY ...
> > > > public class AudioProcessor extends Activity {
> > > >         private AudioInterface service;
> > > >         private ServiceConnection svcConn = new ServiceConnection(){
> > > >                 public void onServiceConnected(ComponentName className, 
> > > > IBinder
> > > > binder){
> > > >                         service = 
> > > > AudioInterface.Stub.asInterface(binder);
> > > >                 }
> > > >                 public void onServiceDisconnected(ComponentName 
> > > > className){
> > > >                         service = null;//NL = probably do more in 
> > > > onService methods
> > > >                 }
> > > >         };
> > > >         private BroadcastReceiver receiver = new BroadcastReceiver(){
> > > >                 public void onReceive(Context context, Intent intent){
> > > >                         Log.d("SHOWING!!!", 
> > > > "!!!");
> > > >                         showMessage(context, intent);
> > > >                 }
> > > >         };
> > > >         @Override
> > > >         public void onCreate(Bundle savedInstanceState) {
> > > >                 super.onCreate(savedInstanceState);
> > > >         setContentView(R.layout.main);
> > > >                 Intent serviceIntent = new Intent(this, 
> > > > AudioService.class);
> > > >                 bindService(serviceIntent, svcConn, BIND_AUTO_CREATE);
> > > >                 registerReceiver(receiver, new IntentFilter
> > > > (AudioService.BROADCAST_ACTION));
> > > >                 serviceIntent.setAction
> > > > ("com.linnell.audioprocessor.AudioService");
> > > >                 startService(serviceIntent);*/
> > > >         }
> > > >         public void showMessage(Context context, Intent intent){
> > > >                 Log.d("SHOWING!!!", "!!!");
> > > >                 try{
> > > >                         String message = service.showMessage();
> > > >                         new 
> > > > AlertDialog.Builder(this).setTitle("Suggestion")
> > > >                         .setMessage(message)
> > > >                         .setNeutralButton("Close", new 
> > > > DialogInterface.OnClickListener(){
> > > >                                 public void onClick(DialogInterface 
> > > > dlg, int sumthin){
> > > >                                         //do nothing 

[android-developers] Re: Broadcast Receiver and Remote Service

2010-01-20 Thread jotobjects
The serviceHandler object you have there now doesn't seem to do
anything useful.  You just need to start the loop in a thread so it
doesn't block the event loop for the Service.  A complete redesign as
Dianne suggests is probably better (and as you said maybe there is no
reason for having a Service at all), but you might try to get what you
have working first.

On Jan 20, 3:32 pm, Natalie  wrote:
> Thanks so much for the response.  But if the long loop (which updates
> the field that needs to find its way to the activity) is in a
> different thread from the one that processes the showMessage call,
> won't I have to switch to doing the communication through the
> Handler?  And at that point I'm beginning to wonder if it makes sense
> to bother with the service or if I should just be doing the work on
> different threads and communicating through the Handlers?  Or am I
> missing something?  Maybe the example you posted will clear all this
> up though, I'll look at that now.  :)
>
> On Jan 20, 3:24 pm, jotobjects  wrote:
>
> > Hi Natalie -
>
> > Not sure what you mean by service you "spawned onto its own thread".
>
> > In any case, it looks like the Service is going to be pretty busy in
> > that while(1) loop so it is not too surprising that it is not
> > available to process the showMessage call.  :)  Yes they are two
> > different threads.  The Activity is blocking on the call to the
> > service that is forever busy in the for loop.
>
> > I think you need to put that loop in a thread and then you need a
> > different Runnable for the handler post().  Here is an example -
>
> >http://developer.android.com/resources/faq/commontasks.html#threading
>
> > Also the serviceHandler.post(myProcess) in onCreate is a duplicate.
> > This is where you need something like startLongWhileLoop() that
> > creates a thread instead.
>
> > On Jan 20, 2:49 pm, Natalie  wrote:
>
> > > Thanks for the response.
> > > I'm pretty sure that's not it because I've put a debug statement first
> > > off in the broadcast receiver's onReceive method and that isn't
> > > appearing either.  It almost seems that the activity's thread just
> > > isn't getting switched to - so far I've only tested in the emulator,
> > > could the emulator not be switching back to the activity's thread?
> > > I've posted the seemingly relevant chunks of code below if that helps.
>
> > > ACTIVITY ...
> > > public class AudioProcessor extends Activity {
> > >         private AudioInterface service;
> > >         private ServiceConnection svcConn = new ServiceConnection(){
> > >                 public void onServiceConnected(ComponentName className, 
> > > IBinder
> > > binder){
> > >                         service = AudioInterface.Stub.asInterface(binder);
> > >                 }
> > >                 public void onServiceDisconnected(ComponentName 
> > > className){
> > >                         service = null;//NL = probably do more in 
> > > onService methods
> > >                 }
> > >         };
> > >         private BroadcastReceiver receiver = new BroadcastReceiver(){
> > >                 public void onReceive(Context context, Intent intent){
> > >                         Log.d("SHOWING!!!", 
> > > "!!!");
> > >                         showMessage(context, intent);
> > >                 }
> > >         };
> > >         @Override
> > >         public void onCreate(Bundle savedInstanceState) {
> > >                 super.onCreate(savedInstanceState);
> > >         setContentView(R.layout.main);
> > >                 Intent serviceIntent = new Intent(this, 
> > > AudioService.class);
> > >                 bindService(serviceIntent, svcConn, BIND_AUTO_CREATE);
> > >                 registerReceiver(receiver, new IntentFilter
> > > (AudioService.BROADCAST_ACTION));
> > >                 serviceIntent.setAction
> > > ("com.linnell.audioprocessor.AudioService");
> > >                 startService(serviceIntent);*/
> > >         }
> > >         public void showMessage(Context context, Intent intent){
> > >                 Log.d("SHOWING!!!", "!!!");
> > >                 try{
> > >                         String message = service.showMessage();
> > >                         new 
> > > AlertDialog.Builder(this).setTitle("Suggestion")
> > >                         .setMessage(message)
> > >                         .setNeutralButton("Close", new 
> > > DialogInterface.OnClickListener(){
> > >                                 public void onClick(DialogInterface dlg, 
> > > int sumthin){
> > >                                         //do nothing - it will close on 
> > > its own
> > >                                 }
> > >                         })
> > >                         .show();
> > >                 }
> > >                 catch(final Throwable t){
> > >                         Log.e("ERROR", "ERROR IN CODE");
> > >                         svcConn.onServiceDisconnected(null);
> > >                 }}}
>
> > > 

[android-developers] Re: Broadcast Receiver and Remote Service

2010-01-20 Thread Natalie
Hi Dianne,
I initially had the service as a local service, but my application was
getting Application Not Responding messages.  Since I'll never have
more than one application binding to my service, I think I'm just
going to abandon the service approach and try the approach in the
example jotobjects posted - I can't see any reason that having it as a
service is useful, but am I missing something?
Thanks!!


On Jan 20, 3:32 pm, Natalie  wrote:
> Thanks so much for the response.  But if the long loop (which updates
> the field that needs to find its way to the activity) is in a
> different thread from the one that processes the showMessage call,
> won't I have to switch to doing the communication through the
> Handler?  And at that point I'm beginning to wonder if it makes sense
> to bother with the service or if I should just be doing the work on
> different threads and communicating through the Handlers?  Or am I
> missing something?  Maybe the example you posted will clear all this
> up though, I'll look at that now.  :)
>
> On Jan 20, 3:24 pm, jotobjects  wrote:
>
>
>
> > Hi Natalie -
>
> > Not sure what you mean by service you "spawned onto its own thread".
>
> > In any case, it looks like the Service is going to be pretty busy in
> > that while(1) loop so it is not too surprising that it is not
> > available to process the showMessage call.  :)  Yes they are two
> > different threads.  The Activity is blocking on the call to the
> > service that is forever busy in the for loop.
>
> > I think you need to put that loop in a thread and then you need a
> > different Runnable for the handler post().  Here is an example -
>
> >http://developer.android.com/resources/faq/commontasks.html#threading
>
> > Also the serviceHandler.post(myProcess) in onCreate is a duplicate.
> > This is where you need something like startLongWhileLoop() that
> > creates a thread instead.
>
> > On Jan 20, 2:49 pm, Natalie  wrote:
>
> > > Thanks for the response.
> > > I'm pretty sure that's not it because I've put a debug statement first
> > > off in the broadcast receiver's onReceive method and that isn't
> > > appearing either.  It almost seems that the activity's thread just
> > > isn't getting switched to - so far I've only tested in the emulator,
> > > could the emulator not be switching back to the activity's thread?
> > > I've posted the seemingly relevant chunks of code below if that helps.
>
> > > ACTIVITY ...
> > > public class AudioProcessor extends Activity {
> > >         private AudioInterface service;
> > >         private ServiceConnection svcConn = new ServiceConnection(){
> > >                 public void onServiceConnected(ComponentName className, 
> > > IBinder
> > > binder){
> > >                         service = AudioInterface.Stub.asInterface(binder);
> > >                 }
> > >                 public void onServiceDisconnected(ComponentName 
> > > className){
> > >                         service = null;//NL = probably do more in 
> > > onService methods
> > >                 }
> > >         };
> > >         private BroadcastReceiver receiver = new BroadcastReceiver(){
> > >                 public void onReceive(Context context, Intent intent){
> > >                         Log.d("SHOWING!!!", 
> > > "!!!");
> > >                         showMessage(context, intent);
> > >                 }
> > >         };
> > >         @Override
> > >         public void onCreate(Bundle savedInstanceState) {
> > >                 super.onCreate(savedInstanceState);
> > >         setContentView(R.layout.main);
> > >                 Intent serviceIntent = new Intent(this, 
> > > AudioService.class);
> > >                 bindService(serviceIntent, svcConn, BIND_AUTO_CREATE);
> > >                 registerReceiver(receiver, new IntentFilter
> > > (AudioService.BROADCAST_ACTION));
> > >                 serviceIntent.setAction
> > > ("com.linnell.audioprocessor.AudioService");
> > >                 startService(serviceIntent);*/
> > >         }
> > >         public void showMessage(Context context, Intent intent){
> > >                 Log.d("SHOWING!!!", "!!!");
> > >                 try{
> > >                         String message = service.showMessage();
> > >                         new 
> > > AlertDialog.Builder(this).setTitle("Suggestion")
> > >                         .setMessage(message)
> > >                         .setNeutralButton("Close", new 
> > > DialogInterface.OnClickListener(){
> > >                                 public void onClick(DialogInterface dlg, 
> > > int sumthin){
> > >                                         //do nothing - it will close on 
> > > its own
> > >                                 }
> > >                         })
> > >                         .show();
> > >                 }
> > >                 catch(final Throwable t){
> > >                         Log.e("ERROR", "ERROR IN CODE");
> > >                         svcConn.onServiceDis

[android-developers] Re: Broadcast Receiver and Remote Service

2010-01-20 Thread Natalie
Thanks so much for the response.  But if the long loop (which updates
the field that needs to find its way to the activity) is in a
different thread from the one that processes the showMessage call,
won't I have to switch to doing the communication through the
Handler?  And at that point I'm beginning to wonder if it makes sense
to bother with the service or if I should just be doing the work on
different threads and communicating through the Handlers?  Or am I
missing something?  Maybe the example you posted will clear all this
up though, I'll look at that now.  :)

On Jan 20, 3:24 pm, jotobjects  wrote:
> Hi Natalie -
>
> Not sure what you mean by service you "spawned onto its own thread".
>
> In any case, it looks like the Service is going to be pretty busy in
> that while(1) loop so it is not too surprising that it is not
> available to process the showMessage call.  :)  Yes they are two
> different threads.  The Activity is blocking on the call to the
> service that is forever busy in the for loop.
>
> I think you need to put that loop in a thread and then you need a
> different Runnable for the handler post().  Here is an example -
>
> http://developer.android.com/resources/faq/commontasks.html#threading
>
> Also the serviceHandler.post(myProcess) in onCreate is a duplicate.
> This is where you need something like startLongWhileLoop() that
> creates a thread instead.
>
> On Jan 20, 2:49 pm, Natalie  wrote:
>
>
>
> > Thanks for the response.
> > I'm pretty sure that's not it because I've put a debug statement first
> > off in the broadcast receiver's onReceive method and that isn't
> > appearing either.  It almost seems that the activity's thread just
> > isn't getting switched to - so far I've only tested in the emulator,
> > could the emulator not be switching back to the activity's thread?
> > I've posted the seemingly relevant chunks of code below if that helps.
>
> > ACTIVITY ...
> > public class AudioProcessor extends Activity {
> >         private AudioInterface service;
> >         private ServiceConnection svcConn = new ServiceConnection(){
> >                 public void onServiceConnected(ComponentName className, 
> > IBinder
> > binder){
> >                         service = AudioInterface.Stub.asInterface(binder);
> >                 }
> >                 public void onServiceDisconnected(ComponentName className){
> >                         service = null;//NL = probably do more in onService 
> > methods
> >                 }
> >         };
> >         private BroadcastReceiver receiver = new BroadcastReceiver(){
> >                 public void onReceive(Context context, Intent intent){
> >                         Log.d("SHOWING!!!", "!!!");
> >                         showMessage(context, intent);
> >                 }
> >         };
> >         @Override
> >         public void onCreate(Bundle savedInstanceState) {
> >                 super.onCreate(savedInstanceState);
> >         setContentView(R.layout.main);
> >                 Intent serviceIntent = new Intent(this, AudioService.class);
> >                 bindService(serviceIntent, svcConn, BIND_AUTO_CREATE);
> >                 registerReceiver(receiver, new IntentFilter
> > (AudioService.BROADCAST_ACTION));
> >                 serviceIntent.setAction
> > ("com.linnell.audioprocessor.AudioService");
> >                 startService(serviceIntent);*/
> >         }
> >         public void showMessage(Context context, Intent intent){
> >                 Log.d("SHOWING!!!", "!!!");
> >                 try{
> >                         String message = service.showMessage();
> >                         new AlertDialog.Builder(this).setTitle("Suggestion")
> >                         .setMessage(message)
> >                         .setNeutralButton("Close", new 
> > DialogInterface.OnClickListener(){
> >                                 public void onClick(DialogInterface dlg, 
> > int sumthin){
> >                                         //do nothing - it will close on its 
> > own
> >                                 }
> >                         })
> >                         .show();
> >                 }
> >                 catch(final Throwable t){
> >                         Log.e("ERROR", "ERROR IN CODE");
> >                         svcConn.onServiceDisconnected(null);
> >                 }}}
>
> > SERVICE ...
> >         public static final String BROADCAST_ACTION = "new_message";
> >         private Intent broadcast = new Intent(BROADCAST_ACTION);
> >         private Handler serviceHandler;
> >         private Process myProcess;
> >         public IBinder onBind(Intent intent) {
> >                 return mBinder;
> >         }
>
> >         @Override public void onCreate() {
> >                 super.onCreate();
> >                 myProcess = new Process();
> >                 serviceHandler = new Handler();
> >                 serviceHandler.post(myProcess);
> >         }
> > 

Re: [android-developers] Re: Broadcast Receiver and Remote Service

2010-01-20 Thread Dianne Hackborn
Also, you should consider having the client supply a callback interface
instead of using a broadcast to communicate with it.  The RemoteService
includes this as part of its example.  (And just to be sure -- do you
-really- need a remote service?  If there is no need for it to run in a
separate process from the client, then making it a local service greatly
simplifies your interaction with it.)

On Wed, Jan 20, 2010 at 3:24 PM, jotobjects  wrote:

> Hi Natalie -
>
> Not sure what you mean by service you "spawned onto its own thread".
>
> In any case, it looks like the Service is going to be pretty busy in
> that while(1) loop so it is not too surprising that it is not
> available to process the showMessage call.  :)  Yes they are two
> different threads.  The Activity is blocking on the call to the
> service that is forever busy in the for loop.
>
> I think you need to put that loop in a thread and then you need a
> different Runnable for the handler post().  Here is an example -
>
> http://developer.android.com/resources/faq/commontasks.html#threading
>
> Also the serviceHandler.post(myProcess) in onCreate is a duplicate.
> This is where you need something like startLongWhileLoop() that
> creates a thread instead.
>
> On Jan 20, 2:49 pm, Natalie  wrote:
> > Thanks for the response.
> > I'm pretty sure that's not it because I've put a debug statement first
> > off in the broadcast receiver's onReceive method and that isn't
> > appearing either.  It almost seems that the activity's thread just
> > isn't getting switched to - so far I've only tested in the emulator,
> > could the emulator not be switching back to the activity's thread?
> > I've posted the seemingly relevant chunks of code below if that helps.
> >
> > ACTIVITY ...
> > public class AudioProcessor extends Activity {
> > private AudioInterface service;
> > private ServiceConnection svcConn = new ServiceConnection(){
> > public void onServiceConnected(ComponentName className,
> IBinder
> > binder){
> > service =
> AudioInterface.Stub.asInterface(binder);
> > }
> > public void onServiceDisconnected(ComponentName
> className){
> > service = null;//NL = probably do more in
> onService methods
> > }
> > };
> > private BroadcastReceiver receiver = new BroadcastReceiver(){
> > public void onReceive(Context context, Intent intent){
> > Log.d("SHOWING!!!",
> "!!!");
> > showMessage(context, intent);
> > }
> > };
> > @Override
> > public void onCreate(Bundle savedInstanceState) {
> > super.onCreate(savedInstanceState);
> > setContentView(R.layout.main);
> > Intent serviceIntent = new Intent(this,
> AudioService.class);
> > bindService(serviceIntent, svcConn, BIND_AUTO_CREATE);
> > registerReceiver(receiver, new IntentFilter
> > (AudioService.BROADCAST_ACTION));
> > serviceIntent.setAction
> > ("com.linnell.audioprocessor.AudioService");
> > startService(serviceIntent);*/
> > }
> > public void showMessage(Context context, Intent intent){
> > Log.d("SHOWING!!!", "!!!");
> > try{
> > String message = service.showMessage();
> > new
> AlertDialog.Builder(this).setTitle("Suggestion")
> > .setMessage(message)
> > .setNeutralButton("Close", new
> DialogInterface.OnClickListener(){
> > public void onClick(DialogInterface dlg,
> int sumthin){
> > //do nothing - it will close on
> its own
> > }
> > })
> > .show();
> > }
> > catch(final Throwable t){
> > Log.e("ERROR", "ERROR IN CODE");
> > svcConn.onServiceDisconnected(null);
> > }}}
> >
> > SERVICE ...
> > public static final String BROADCAST_ACTION = "new_message";
> > private Intent broadcast = new Intent(BROADCAST_ACTION);
> > private Handler serviceHandler;
> > private Process myProcess;
> > public IBinder onBind(Intent intent) {
> > return mBinder;
> > }
> >
> > @Override public void onCreate() {
> > super.onCreate();
> > myProcess = new Process();
> > serviceHandler = new Handler();
> > serviceHandler.post(myProcess);
> > }
> > @Override public void onDestroy() {
> > super.onDestroy();
> > shutdownService();
> > }
> > private final Audio

[android-developers] Re: Broadcast Receiver and Remote Service

2010-01-20 Thread jotobjects
Hi Natalie -

Not sure what you mean by service you "spawned onto its own thread".

In any case, it looks like the Service is going to be pretty busy in
that while(1) loop so it is not too surprising that it is not
available to process the showMessage call.  :)  Yes they are two
different threads.  The Activity is blocking on the call to the
service that is forever busy in the for loop.

I think you need to put that loop in a thread and then you need a
different Runnable for the handler post().  Here is an example -

http://developer.android.com/resources/faq/commontasks.html#threading

Also the serviceHandler.post(myProcess) in onCreate is a duplicate.
This is where you need something like startLongWhileLoop() that
creates a thread instead.

On Jan 20, 2:49 pm, Natalie  wrote:
> Thanks for the response.
> I'm pretty sure that's not it because I've put a debug statement first
> off in the broadcast receiver's onReceive method and that isn't
> appearing either.  It almost seems that the activity's thread just
> isn't getting switched to - so far I've only tested in the emulator,
> could the emulator not be switching back to the activity's thread?
> I've posted the seemingly relevant chunks of code below if that helps.
>
> ACTIVITY ...
> public class AudioProcessor extends Activity {
>         private AudioInterface service;
>         private ServiceConnection svcConn = new ServiceConnection(){
>                 public void onServiceConnected(ComponentName className, 
> IBinder
> binder){
>                         service = AudioInterface.Stub.asInterface(binder);
>                 }
>                 public void onServiceDisconnected(ComponentName className){
>                         service = null;//NL = probably do more in onService 
> methods
>                 }
>         };
>         private BroadcastReceiver receiver = new BroadcastReceiver(){
>                 public void onReceive(Context context, Intent intent){
>                         Log.d("SHOWING!!!", "!!!");
>                         showMessage(context, intent);
>                 }
>         };
>         @Override
>         public void onCreate(Bundle savedInstanceState) {
>                 super.onCreate(savedInstanceState);
>         setContentView(R.layout.main);
>                 Intent serviceIntent = new Intent(this, AudioService.class);
>                 bindService(serviceIntent, svcConn, BIND_AUTO_CREATE);
>                 registerReceiver(receiver, new IntentFilter
> (AudioService.BROADCAST_ACTION));
>                 serviceIntent.setAction
> ("com.linnell.audioprocessor.AudioService");
>                 startService(serviceIntent);*/
>         }
>         public void showMessage(Context context, Intent intent){
>                 Log.d("SHOWING!!!", "!!!");
>                 try{
>                         String message = service.showMessage();
>                         new AlertDialog.Builder(this).setTitle("Suggestion")
>                         .setMessage(message)
>                         .setNeutralButton("Close", new 
> DialogInterface.OnClickListener(){
>                                 public void onClick(DialogInterface dlg, int 
> sumthin){
>                                         //do nothing - it will close on its 
> own
>                                 }
>                         })
>                         .show();
>                 }
>                 catch(final Throwable t){
>                         Log.e("ERROR", "ERROR IN CODE");
>                         svcConn.onServiceDisconnected(null);
>                 }}}
>
> SERVICE ...
>         public static final String BROADCAST_ACTION = "new_message";
>         private Intent broadcast = new Intent(BROADCAST_ACTION);
>         private Handler serviceHandler;
>         private Process myProcess;
>         public IBinder onBind(Intent intent) {
>                 return mBinder;
>         }
>
>         @Override public void onCreate() {
>                 super.onCreate();
>                 myProcess = new Process();
>                 serviceHandler = new Handler();
>                 serviceHandler.post(myProcess);
>         }
>         @Override public void onDestroy() {
>                 super.onDestroy();
>                 shutdownService();
>         }
>         private final AudioInterface.Stub mBinder = new AudioInterface.Stub()
> {
>                 public String showMessage(){
>                         serviceHandler.post(myProcess);
>                         return message;
>                 }
>                 public void stopService(){}
>
>         };
>         class Process implements Runnable{
>                 public void run(){
> //run then sits on a while(1), occasionally doing a sendBroadcast
> (broadcast);
>
> I know a lot of the stuff in onCreate would be better in onResume, etc
> - I'm planning on cleaning all this up once the functionality is
> there.  :)
>
> On Jan 20, 2:21 pm, Kevin Duffey  w

[android-developers] Re: Broadcast Receiver and Remote Service

2010-01-20 Thread Natalie
Thanks for the response.
I'm pretty sure that's not it because I've put a debug statement first
off in the broadcast receiver's onReceive method and that isn't
appearing either.  It almost seems that the activity's thread just
isn't getting switched to - so far I've only tested in the emulator,
could the emulator not be switching back to the activity's thread?
I've posted the seemingly relevant chunks of code below if that helps.

ACTIVITY ...
public class AudioProcessor extends Activity {
private AudioInterface service;
private ServiceConnection svcConn = new ServiceConnection(){
public void onServiceConnected(ComponentName className, IBinder
binder){
service = AudioInterface.Stub.asInterface(binder);
}
public void onServiceDisconnected(ComponentName className){
service = null;//NL = probably do more in onService 
methods
}
};
private BroadcastReceiver receiver = new BroadcastReceiver(){
public void onReceive(Context context, Intent intent){
Log.d("SHOWING!!!", "!!!");
showMessage(context, intent);
}
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Intent serviceIntent = new Intent(this, AudioService.class);
bindService(serviceIntent, svcConn, BIND_AUTO_CREATE);
registerReceiver(receiver, new IntentFilter
(AudioService.BROADCAST_ACTION));
serviceIntent.setAction
("com.linnell.audioprocessor.AudioService");
startService(serviceIntent);*/
}
public void showMessage(Context context, Intent intent){
Log.d("SHOWING!!!", "!!!");
try{
String message = service.showMessage();
new AlertDialog.Builder(this).setTitle("Suggestion")
.setMessage(message)
.setNeutralButton("Close", new 
DialogInterface.OnClickListener(){
public void onClick(DialogInterface dlg, int 
sumthin){
//do nothing - it will close on its own
}
})
.show();
}
catch(final Throwable t){
Log.e("ERROR", "ERROR IN CODE");
svcConn.onServiceDisconnected(null);
}}}

SERVICE ...
public static final String BROADCAST_ACTION = "new_message";
private Intent broadcast = new Intent(BROADCAST_ACTION);
private Handler serviceHandler;
private Process myProcess;
public IBinder onBind(Intent intent) {
return mBinder;
}

@Override public void onCreate() {
super.onCreate();
myProcess = new Process();
serviceHandler = new Handler();
serviceHandler.post(myProcess);
}
@Override public void onDestroy() {
super.onDestroy();
shutdownService();
}
private final AudioInterface.Stub mBinder = new AudioInterface.Stub()
{
public String showMessage(){
serviceHandler.post(myProcess);
return message;
}
public void stopService(){}

};
class Process implements Runnable{
public void run(){
//run then sits on a while(1), occasionally doing a sendBroadcast
(broadcast);

I know a lot of the stuff in onCreate would be better in onResume, etc
- I'm planning on cleaning all this up once the functionality is
there.  :)



On Jan 20, 2:21 pm, Kevin Duffey  wrote:
> I am not entirely sure if I understand.. but is it possible when you raise
> the alert dialog, it's a different activity and that may be why it seems
> it's not working? Maybe you have to do something in the alert dialog... or
> maybe it blocks the main activity thread and that is why?
>
>
>
> On Wed, Jan 20, 2010 at 2:10 PM, Natalie  wrote:
> > Hi everyone,
> > I'm hoping to do some audio processing in a remote service (service
> > I've spawned onto its own thread); this will basically occur in a while
> > (1) loop - so constant processing.  Occasionally I want to provide
> > some information back to the activity that is bound to the service;
> > I'm doing this by sending a broadcast from the service, that is
> > received by a broadcast receiver on the activity, which then uses the
> > activity's service connection to call into the service and get the
> > information needed; at this point the broadcast receiver makes an
> > alert dialog presenting the inform

[android-developers] Re: Broadcast Receiver not getting called when expected

2010-01-17 Thread Albert
If you long click the "cancel call" button on the emulator you will
the phone options where you can set the airplane mode to "on", that
way you will receive the broadcast. Remmember when you test this that
the emulator is actually using your computer's network so you will
need to disable that as well.

Hope it helps!

On Jan 17, 1:02 pm, DroidAttack  wrote:
> Hi,
> I have the same issue but I cannot seem to find a way to
> "disconnect the connectivity on the emulator" as you described in your
> solution.
> Can you please describe how this can be done.
> Thanks.
>
> On Dec 28 2009, 7:40 pm, Albert  wrote:
>
> > solved! it appears that the emulator would not send the broadcast only
> > by not being connected, you also have to disconect it on the emulator.
> > Maybe in the future releases it will be better sync with the pc...
>
>
-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: Broadcast Receiver not getting called when expected

2010-01-17 Thread DroidAttack
Hi,
I have the same issue but I cannot seem to find a way to
"disconnect the connectivity on the emulator" as you described in your
solution.
Can you please describe how this can be done.
Thanks.


On Dec 28 2009, 7:40 pm, Albert  wrote:
> solved! it appears that the emulator would not send the broadcast only
> by not being connected, you also have to disconect it on the emulator.
> Maybe in the future releases it will be better sync with the pc...
-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: Broadcast Receiver works sometimes/sometimes not.

2010-01-06 Thread jwei512
I'm pretty sure it's because in the manifest, if the package is
"com.test" then when you declare Activities/Services/Receivers the
package name is already assumed... so if you do:



Then this is actually com.test.BootBroadcastReceiver, and if you do:



Then I'm pretty sure the path is actually
com.test.com.test.BootBroadcastReceiver which obviously doesn't exist
in your project

But yes, please correct me if I'm wrong, but I'm pretty sure this is
why...

- jwei

http://thinkandroid.wordpress.com

On Jan 6, 2:12 am, Android Development  wrote:
> Hello,
>
> I wish to listen to  android.intent.action.BOOT_COMPLETED.
>
> However i am not getting the broadcast intent, if i specify
> com.test.BootBroadcastReceiver in the manifest.
>
> When i change this value to simply BootBroadcastReceiver, then i am getting
> the broadcast intent.
>
> 
>
>        
>          
>        
>
>  
>
> My package in the manifest file is:
>
> http://schemas.android.com/apk/res/android";
>       package="com.test"
>
> and the BootBroadcastReceiver resides in this package.
>
> What is the reason behind this ?
>
> Thanks in advance
-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: Broadcast Receiver not getting called when expected

2009-12-28 Thread Albert
solved! it appears that the emulator would not send the broadcast only
by not being connected, you also have to disconect it on the emulator.
Maybe in the future releases it will be better sync with the pc...

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: broadcast Receiver for action android.intent.action.MAIN

2009-10-03 Thread Mark Murphy

> I was wondering if its possible to have a broadcast receiver to listen
> when the app its in launches.  I tried doing by creating a
> BroadcastReceiver to listen for the android.intent.action.MAIN action
> but it never gets called?  Is there something I need to do or a
> different action I should be listening for?

Starting an activity does not involve a broadcast Intent, AFAIK. It
involves an *Intent*, but that Intent is not broadcast, but rather is used
solely to identify the activity to run.

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com
Android App Developer Books: http://commonsware.com/books.html



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---



[android-developers] Re: broadcast Receiver for action android.intent.action.MAIN

2009-10-03 Thread RichardC

Try adding



to the receiver intent-filter.

I don't think this will work but I am interested to see what result
you get :)

--
RichardC

On Oct 3, 12:38 pm, "jonathan.duty"  wrote:
> I was wondering if its possible to have a broadcast receiver to listen
> when the app its in launches.  I tried doing by creating a
> BroadcastReceiver to listen for the android.intent.action.MAIN action
> but it never gets called?  Is there something I need to do or a
> different action I should be listening for?
>
> Here is my manifest xml:
>
> 
> http://schemas.android.com/apk/res/android";
>       package="com.jonandkerry.helloworld"
>       android:versionCode="1"
>       android:versionName="1.0">
>     
>
>                            android:label="@string/app_name">
>             
>                 
>                  android:name="android.intent.category.LAUNCHER" />
>             
>         
>
>         
>                         
>                                  android:name="android.intent.action.MAIN" />
>                         
>         
>
> 
>
>     
>
>     
>
> 
>
> 
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---



[android-developers] Re: Broadcast receiver

2009-09-28 Thread Mark Murphy

richarth wrote:
> Hi,
> 
> I'm trying to create a broadcast receiver which responds to system
> events and change system settings.  I don't need any interaction from
> the user so I don't need an activity and have been trying to do
> everything through the manifest file.  I've put a log event into my
> onReceive method but it never logs anything so I'm presuming my method
> is never called.  I've tried this with both the 1.5 and 1.6 SDKs.  I
> was hoping somebody could have a look at my code please and let me
> know if there are any problems.
> 
> Manifest file
> 
> 
> http://schemas.android.com/apk/res/android";
>   package="uk.co.richarth"
>   android:versionCode="1"
>   android:versionName="1.0">
> 
> 
> 
>  android:permission="android.permission.ACCESS_NETWORK_STATE"
> android:enabled="true" android:name=".BroadcastReceiverExample">
> 
>  android:name="android.intent.action.AIRPLANE_MODE_CHANGED">
> 
> 
> 
> 
> 
>  android:name="android.permission.ACCESS_NETWORK_STATE"> permission>
> 
> 
> 
> Class
> 
> package uk.co.richarth;
> 
> import android.content.BroadcastReceiver;
> import android.content.Context;
> import android.content.Intent;
> import android.util.Log;
> 
> public class BroadcastReceiverExample extends BroadcastReceiver {
> 
>   @Override
>   public void onReceive(Context arg0, Intent arg1) {
>   Log.d("debug", "working");
> 
>   }
> 
> }
> 
> Thanks for the help

You just want your  element, not the android:permission
attribute. Also, you may wish to move that  up earlier
in the XML -- some of this stuff seems (unfortunately) a bit
position-dependent.

Nothing else leaps out at me. Check logcat and see if you get any
warnings -- if Android has difficulty invoking some component, that
tends to get logged as a warning.

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

Need Android talent? Ask on HADO! http://wiki.andmob.org/hado

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---