[android-developers] Bluetooth GATT characteristic thread safety

2014-07-20 Thread flix
As for most APIs, there is no word about thread safety in the Bluetooth 
GATT API documentation.

I have implemented a driver for the HM-10 BLE module, which is an UART 
adapter. It has one GATT characteristic for reading and writing data. So I 
get notifications about incoming data in the onCharacteristicChanged() 
callback function of my BluetoothGattCallback implementation. These 
callbacks are called from a Binder thread which the Android framework 
maintains. To write data, I need to call setValue() on the 
BluetoothGattCharacteristic object and call writeCharacteristic() on the 
BluetoothGatt instance afterwards. This is done from a thread of my app.

And here is the problem: Unsurprisingly, BluetoothGattCharacteristic is not 
thread safe: What sometimes happens is that the Value property of my 
BluetoothGattCharacteristic gets overwritten during my write operation, 
when incoming data is received in the very same moment.

Any idea how to solve this? Is it somehow possible to place the code for 
writing data in the same thread where the BluetoothGattCallback callbacks 
occur?

-- 
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/d/optout.


[android-developers] Start an activity form a class without extending Activity

2011-01-04 Thread flix
Hello,
   (sorry for my english)
   I have 3 classes in my project. One is the MainActivity (extend
Actvity), another SecondActivity( extend Actvity) and the last
DrawView (extend View). How can I start SecondActivity form DrawView?

-- 
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] IllegalStateException when calling Preference.setDependency()

2009-06-04 Thread flix

Hello,

I'm trying to create a PreferenceScreen with a CheckBoxPreference
which depends on an other CheckBoxPreference using the setDependency()
method, as shown in the code below.

While calling the setDependency() method, I get the following
Exception:
java.lang.IllegalStateException: Dependency preferenceKey1 not found
for preference preferenceKey2 (title: chbPref2
 at android.preference.Preference.registerDependency
(Preference.java:1007)
 at android.preference.Preference.setDependency(Preference.java:
1124)
 at test.preferences.TestPreferencesActivity.createPreferenceScreen
(TestPreferencesActivity.java:28)
 at test.preferences.TestPreferencesActivity.onCreate
(TestPreferencesActivity.java:13)
 at android.app.Instrumentation.callActivityOnCreate
(Instrumentation.java:1123)
 at android.app.ActivityThread.performLaunchActivity
(ActivityThread.java:2231)
 ... 11 more

I have no idea what's wrong with this code. Without the setDependency
() call, the PreferenceScreen works well.

package test.preferences;

import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceManager;
import android.preference.PreferenceScreen;

public class TestPreferencesActivity extends PreferenceActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setPreferenceScreen(this.createPreferenceScreen());
}

private PreferenceScreen createPreferenceScreen() {
PreferenceManager preferenceManager = this.getPreferenceManager
();
PreferenceScreen preferenceScreen =
preferenceManager.createPreferenceScreen(this);

CheckBoxPreference chbPref1 = new CheckBoxPreference(this);
chbPref1.setTitle(chbPref1);
chbPref1.setKey(preferenceKey1);
preferenceScreen.addPreference(chbPref1);

CheckBoxPreference chbPref2 = new CheckBoxPreference(this);
chbPref2.setTitle(chbPref2);
chbPref2.setKey(preferenceKey2);
chbPref2.setDependency(chbPref1.getKey());
preferenceScreen.addPreference(chbPref2);

return preferenceScreen;
}
}
--~--~-~--~~~---~--~~
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] onSaveInstanceState and onRestoreInstanceState are not properly called

2009-02-21 Thread flix

Hello,

in my application, I sometimes start other activities which use the
Theme.Dialog style the to show them like dialogs, as recommended in
the FAQ of the Android documentation. And up to now I overrided the
onSaveInstanceState and onRestoreInstanceState methods in my activity
to store / restore my Activity's state when configuration changes
occur, as shown in the example below.

Now I found out that there is a problem with that:
* When the other activity (ActivityB in my example) is started,
ActivityA's onSaveInstanceState is called (why?).
* While changing the screen orientation when ActivityB is shown in the
foreground and ActivityA in the background, onSaveInstanceState and
onRestoreInstanceState are not called for ActivityA.

In my example, this means that the content of the textbox of ActivityA
is properly restored when ActivityB is shown in the foreground only on
the first screen orientation change, but not when changing the
orientation for a second time.

Using the savedInstanceState bundle I get in my onCreate method
instead of using onRestoreInstanceState does not solve the problem for
me, because the stored values in the bundle get lost in the scenario I
described above.

What is wrong with the approach I chose?

--

package test.activitysave;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;

public class ActivityA extends Activity {
  private EditText txbTest;

  @Override
  public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

LinearLayout layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.VERTICAL);

txbTest = new EditText(this);
layout.addView(txbTest,
new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));

Button button = new Button(this);
button.setText(Start activity...);
button.setOnClickListener(new View.OnClickListener() {
  @Override
  public void onClick(View v) {
Intent intent = new Intent(ActivityA.this, ActivityB.class);
ActivityA.this.startActivity(intent);
  }
});
layout.addView(button,
new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));

setContentView(layout);
  }

  @Override
  protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
this.txbTest.setText(savedInstanceState.getCharSequence
(ENTERED_TEXT));
  }

  @Override
  protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putCharSequence(ENTERED_TEXT, this.txbTest.getText());
  }
}

--~--~-~--~~~---~--~~
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: Listview click event with button

2008-10-28 Thread flix

I had the same problem. A simple button.setFocusable(false) solved the
problem for me.

On 16 Okt., 20:03, goldfish [EMAIL PROTECTED] wrote:
 Hello,

 I have a custom listview contol that performs on click event handling
 when a user clicks a list item. When I add a button to each listview
 item my listview click event stops working and only my button's click
 event fires. If I remove the button the listview's click event fires
 correctly. Is there a way to have both click events fire correctly?
 Thanks
--~--~-~--~~~---~--~~
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
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---



[android-developers] Is MapView without roads possible?

2008-08-30 Thread flix

Hello,

I'm using the Google Maps API in my application (in satellite mode).
But for my aim, it is rather disturbing that there are always the
roads (and their numbers) shown on the map. Is it possible to
deactivate them? I tried to deactivate traffic using the setTraffic()
method, but this has no effect (I don't know what effect this is
supposed to have).
--~--~-~--~~~---~--~~
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
[EMAIL PROTECTED]
Announcing the new Android 0.9 SDK beta!
http://android-developers.blogspot.com/2008/08/announcing-beta-release-of-android-sdk.html
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---