Go Back   Android Forums > Android Discussion > Android Applications
Android Applications All the information you could ever want about Android Applications. Learn about apps and get help with them... all here! New apps can be found and announced in the Applications Announcements forum linked below.
Gamers - Check out our new sister sites!
Nintendo Wii U!    |    OUYA - $99 Android System!

test: Reply
 
LinkBack Thread Tools
Old March 7th, 2011, 07:48 AM   #1 (permalink)
Junior Member
Thread Author (OP)
 
Join Date: Mar 2011
Posts: 67
 
Device(s):
Carrier: Not Provided

Thanks: 14
Thanked 4 Times in 4 Posts
Default Android - startActivityForResult outside an Activity?

Hi

I have a wrapper class (BluetoothDiscoverer) which is instantiated within a Service. This class obtains a BluetoothAdapter and checks whether Bluetooth is enabled before scanning for neighbouring devices.

Now if Bluetooth is not enabled I want to be able to do the following within this class (BluetoothDiscoverer):

Code:
Intent enableBluetoothIntent  = new 
Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);

startActivityForResult(enableBluetoothIntent, BLUETOOTH_ENABLER);
Now I have read this: use startActivityForResult from non-activity

but I don't want to pass my Main Activity into this object since I want to deal with the result (whether the user accepts to enable bluetooth or not) within the BluetoothDiscoverer class.

Now If I make BluetoothDiscoverer a subclass of Activity

I seem to be getting a NullPointerException when the startActivityForResult is about to be called.

I think this is because I need to add an onCreate()/onDestroy() method, but this defeats the purpose of what I am doing as I need to be able to call methods on the BluetoothDiscoverer object within the service that instantiates this class.

I also need to register a broadcast receiver for retrieving neighbouring devices when a scan is initiated. If the BluetoothDiscoverer class is not an Activity, how do I register this receiver?

Is there a work around for this?

Thank you
Andreas

kkudi is offline  
Reply With Quote
Sponsors
Old September 30th, 2011, 07:20 AM   #2 (permalink)
New Member
 
Join Date: Sep 2011
Posts: 2
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

I am in the same situation. Did you find solution to your problem ?

Thanks for your reply,
trotimax is offline  
Reply With Quote
Old September 30th, 2011, 07:33 AM   #3 (permalink)
New Member
 
Join Date: Sep 2011
Posts: 2
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

I am in the same situation. Did you find solution to your problem ?

Thanks for your reply,
trotimax is offline  
Reply With Quote
Reply
Tags
activity, android, java


Go Back   Android Forums > Android Discussion > Android Applications
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 12:12 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.