<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Problem with killing process in Android</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/24591/problem-with-killing-process-in-android</link><description>Hello ! 
 I&amp;#39;ve created an app based on the nrf blinky master : it works perfectly on my smartphones.
But when I kill the app, and when I relaunch it, it doesn&amp;#39;t connect (or it connects, but in 2 minutes at least) 
 Do you know why, please ?
I&amp;#39;ve been</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 25 Aug 2017 13:21:28 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/24591/problem-with-killing-process-in-android" /><item><title>RE: Problem with killing process in Android</title><link>https://devzone.nordicsemi.com/thread/96832?ContentTypeID=1</link><pubDate>Fri, 25 Aug 2017 13:21:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3022a2c2-6247-435d-bd58-2ac4aadcbd19</guid><dc:creator>Aleksander Nowakowski</dc:creator><description>&lt;p&gt;I don&amp;#39;t understand. Do you call connectGatt when you launch the app? And you don&amp;#39;t get callback immediately after the connection was done? It&amp;#39;s something very wrong.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem with killing process in Android</title><link>https://devzone.nordicsemi.com/thread/96834?ContentTypeID=1</link><pubDate>Fri, 25 Aug 2017 12:35:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:242323c9-8e7a-41cf-a320-65d7fd9e053f</guid><dc:creator>TheRaven</dc:creator><description>&lt;p&gt;Hello ! I still have a problem : when I re-open the app, the phone connects immediatly to the board, but onConnectionStateChange doesn&amp;#39;t change. Where can I see the function launched during this connection in order to update my connection flag, please ?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem with killing process in Android</title><link>https://devzone.nordicsemi.com/thread/96829?ContentTypeID=1</link><pubDate>Thu, 24 Aug 2017 12:12:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:58d9f653-2475-43e5-8293-fd7adf2f7a96</guid><dc:creator>TheRaven</dc:creator><description>&lt;p&gt;I add a Log.d in the onConnectionStateChange : it is executed immediatly after the connection on the board.
It seems the problem is that a flag that I use to detect the connection was missing it onConnectionStateChange.
I will confirm this quickly after testing it with the board !&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem with killing process in Android</title><link>https://devzone.nordicsemi.com/thread/96828?ContentTypeID=1</link><pubDate>Thu, 24 Aug 2017 11:22:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:877894eb-3c38-4a4b-acb9-78ee2d27c9a3</guid><dc:creator>Aleksander Nowakowski</dc:creator><description>&lt;p&gt;Hmm.. so you get the onConnectionStateChanged callback delayed? That&amp;#39;s very weird. I&amp;#39;d have to see the code.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem with killing process in Android</title><link>https://devzone.nordicsemi.com/thread/96835?ContentTypeID=1</link><pubDate>Thu, 24 Aug 2017 10:20:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:03728274-dba7-4f8a-9788-1d166e0b710f</guid><dc:creator>TheRaven</dc:creator><description>&lt;p&gt;EDIT : When I re-launch the app, the board detect the connection quickly (1-2 seconds), but the app detects the connection after 1 or 2 minutes&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem with killing process in Android</title><link>https://devzone.nordicsemi.com/thread/96830?ContentTypeID=1</link><pubDate>Thu, 24 Aug 2017 09:50:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bee06a23-0aea-4d55-bb92-a2a4605ce4aa</guid><dc:creator>TheRaven</dc:creator><description>&lt;p&gt;Yes : on the launching of the app, I do a scan, and I filter the devices by name, and I connect if the name is one in particular.
Thanks, I&amp;#39;m reading it.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem with killing process in Android</title><link>https://devzone.nordicsemi.com/thread/96831?ContentTypeID=1</link><pubDate>Thu, 24 Aug 2017 09:28:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:03c2f0e9-9252-4c3f-9846-5b2d48e64f61</guid><dc:creator>Aleksander Nowakowski</dc:creator><description>&lt;p&gt;Hi, did you implement reconnecting on your own? As I wrote, when the app is killed the gatt.close() is called and it will no longer reconnect automatically (assuming autoConnect was true). When the app is launched again you have to call connectGatt again (with autoConnect = &amp;quot;is the app in fg&amp;quot;). Keep in mind, that when you device is not bonded nor has a public address and your phone was restarted, you have to scan for your device and an adv packet from it needs to be received at least once so that the system know what address type it has (public or private). By default it assumes a public address so calling&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;BluetoothDevice device = new BluetoothDevice(savedAddress);
... = device.connectGatt(...);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;will fail, as it will try to connect to a public address. Check this: &lt;a href="https://devzone.nordicsemi.com/blogs/1046/what-to-keep-in-mind-when-developing-your-ble-andr/"&gt;devzone.nordicsemi.com/.../&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem with killing process in Android</title><link>https://devzone.nordicsemi.com/thread/96833?ContentTypeID=1</link><pubDate>Thu, 24 Aug 2017 09:11:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0a64ba92-bee6-41f1-a245-0daa034032f1</guid><dc:creator>TheRaven</dc:creator><description>&lt;p&gt;Hello,
Thanks for your answer.
I change &amp;quot;mBluetoothGatt = device.connectGatt(mContext, autoConnect, getGattCallback());&amp;quot; to mBluetoothGatt = device.connectGatt(mContext, false, getGattCallback());
It connects quicker.
BUt again, when I kill the app, it doesn&amp;#39;t reconnect, until I restart manually the Bluetooth.
Do you know what can be the problem ?&lt;/p&gt;
&lt;p&gt;EDIT : in facts, it reconnects, but after 2 minutes !&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem with killing process in Android</title><link>https://devzone.nordicsemi.com/thread/96827?ContentTypeID=1</link><pubDate>Wed, 23 Aug 2017 13:12:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a0370968-79eb-420d-ae67-653c15c84eb8</guid><dc:creator>Aleksander Nowakowski</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I&amp;#39;m not sure if it&amp;#39;s the case, but it may be related to a way how you call &lt;code&gt;device.connectGatt(..., autoConnect, ...)&lt;/code&gt;. The first call should be with &lt;code&gt;autoConnect = false&lt;/code&gt;, as it&amp;#39;s much faster. If you want to keep device connected you also connect with false, but then, when device disconnects, call &lt;code&gt;gatt.connect()&lt;/code&gt; which will use &lt;code&gt;autoConnect = true&lt;/code&gt;. This parameter set to true adds the device to a list in the low level controller, so the CPU doesn&amp;#39;t have to be waken up every time an adv packet is received to check if we should, or should not connect. Controller is power optimized, so it may connect after some time.
When the app is killed (the &lt;code&gt;gatt.close()&lt;/code&gt; was called) the autoConnect should again be set to false so that next connection is quick.&lt;/p&gt;
&lt;p&gt;nRF Blinky wasn&amp;#39;t updated for some time now, please check nRF Toolbox app, a specially the BleManager class (&lt;a href="https://github.com/NordicSemiconductor/Android-nRF-Toolbox/blob/master/app/src/main/java/no/nordicsemi/android/nrftoolbox/profile/BleManager.java"&gt;link&lt;/a&gt;). It makes sure that autoConnect is false on the first call.&lt;/p&gt;
&lt;p&gt;Hope it helped...&lt;/p&gt;
&lt;p&gt;Aleksander&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>