我有一个名为HomeActivity的活动,它有一个SurfaceView并显示一个摄像头预览图片.如果您正在启动/重新启动它,此活动会很安静并且感觉很慢.
所以我做了一些调查,发现,不知何故总是调用onCreate方法.在我看来,如果活动已经开始,这不应该发生?
该文件说:第一次创建活动时调用.这是您应该执行所有常规静态设置的地方:创建视图,将数据绑定到列表等.此方法还为您提供包含活动先前冻结状态的Bundle(如果有).始终紧跟onStart().
这是处理返回的方法:
protected void gotoHome() {
final Intent intent = new Intent(SomeOtherActivity.this, HomeActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}
Run Code Online (Sandbox Code Playgroud)
编辑:
以下是我离开HomeActivity的方式......没什么特别的:
final Intent i = new Intent(HomeActivity.this, SomeOtherActivity.class);
startActivity(i);
Run Code Online (Sandbox Code Playgroud) 我即将实现地理围栏的功能,在我完成任何认真的工作之前,我需要知道在第一次转换后地理围栏是否仍然有效.
该功能的核心是:
每次我在点P的x米范围内(称之为区域A),我都希望动作B出现.
我需要知道的是
Geofence.NEVER_EXPIRE
并确保每次进入指定区域时都会获得PendingIntent,无论是否经过时间,重新启动等等要么
我希望前者是这样的
android geofencing google-play-services android-geofence location-client
每隔一段时间我就得到:
不幸的是,MyApp已经停止了.
如果您有一些日志,问题很容易解决,但在我的情况下,logcat绝对没有错误消息(它有我的应用程序发布的正常消息,其他异常显示在那里但不是这导致这个app has stopped
).
我有没有机会解决这个问题?
好处是我可以很容易地重现它,因此我试图将尽可能多的信息放入logcat然后调查发生了什么.
我已经启动并运行了ACRA(其他例外是由它捕获但不是这个app has stopped
).
当它发生时我的应用程序不可见,并且在IntentService中有一些事情发生.我的应用程序正在跟踪地理围栏,app has stopped
当我在手机设置中打开和关闭位置时,仅在HTC M8上发生.我已经在不同的手机上进行了测试,并且不会发生在LG G3,Nexus 5,Moto G,LG Swift L9上.
我想检查新权限模型的工作原理,所以在应用程序的设置中我禁用了Contacts
.然后我去app并尝试阅读Contacts
...它有点工作:
try {
Uri result = data.getData();
int contentIdx;
cursor = getContentResolver().query(result, null, null, null, null);
contentIdx = cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER);
if(cursor.moveToFirst()) {
content = cursor.getInt(contentIdx);
}
if(content > 0) {
contentIdx = cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME);
if(cursor.moveToFirst()) {
name = cursor.getString(contentIdx);
}
contentIdx = cursor.getColumnIndex(BaseColumns._ID);
if(cursor.moveToFirst()) {
content = cursor.getLong(contentIdx);
}
cursor = managedQuery(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, new String[] { Phone.NUMBER }, Data.CONTACT_ID + "=?", new String[] { String.valueOf(content) }, null);
if(cursor.moveToFirst()) {
number = cursor.getString(cursor.getColumnIndex(Phone.NUMBER));
}
}
} catch (Exception e) { …
Run Code Online (Sandbox Code Playgroud) android android-contacts android-permissions android-6.0-marshmallow
我有Android应用程序暴露BLE服务器.我连接BluetoothGattServer#connect.它有效 - 我的应用程序通过STATE_CONNECTED调用BluetoothGattServerCallback#onConnectionStateChange.当我完成客户端后,我尝试使用BluetoothGattServer#cancelConnection与我的应用程序断开连接.
但我没有接到对BluetoothGattServerCallback#onConnectionStateChange的调用,似乎连接仍然处于活动状态,因为我的BLE客户端没有开始做广告(当没有任何连接时它就会这样做).
在logcat中我只看到:
BluetoothGattServer: cancelConnection() - device: XX:XX:XX:XX:XX:XX
Run Code Online (Sandbox Code Playgroud)
有趣的是,我的应用程序在完全关闭BT后立即调用BluetoothGattServerCallback#onConnectionStateChange和STATE_DISCONNECTED.
android bluetooth-lowenergy android-bluetooth gatt android-ble
我正在开发一个应用程序,并且我不时会得到这个奇怪的消息:
W/SystemClock(11814): time going backwards: prev 9003590393023(ioctl) vs now 9003584533648(ioctl), tid=11856
Run Code Online (Sandbox Code Playgroud)
这是什么意思?为什么会这样?
谢谢!
当我通过http://www.jsonschema2pojo.org/生成POJO时,我得到这样的结果:
import javax.annotation.Generated;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
@Generated("org.jsonschema2pojo")
public class Name {
//...
}
Run Code Online (Sandbox Code Playgroud)
但Android Studio无法识别javax.annotation.Generated
,我必须删除两行代码
import javax.annotation.Generated;
Run Code Online (Sandbox Code Playgroud)
和
@Generated("org.jsonschema2pojo")
Run Code Online (Sandbox Code Playgroud)
形成每一个POJO,这是一种痛苦.有没有办法压制http://www.jsonschema2pojo.org/添加该注释?
按照简单的教程我可以连接到设备(带有ADNS-5000芯片的usb光学鼠标)并制作批量传输.
UsbInterface intf = device.getInterface(0);
UsbEndpoint endpoint = intf.getEndpoint(0);
UsbDeviceConnection connection = manager.openDevice(device);
connection.claimInterface(intf, forceClaim);
connection.bulkTransfer(endpoint, bytes, bytes.length, TIMEOUT); //do in another thread
Run Code Online (Sandbox Code Playgroud)
ADNS-5000规范(可以用google搜索)定义了一些"USB命令",例如:
助记符:Get_Status_Device
命令:80 00 00 00 00 00 02 00
注意:通常返回00 00,自供电00 00,远程唤醒02 00
所以我理解为:当我写数据时:
private byte[] bytes = {(byte) 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00};
Run Code Online (Sandbox Code Playgroud)
我应该得到的设备0x00, 0x00
或0x00, 0x00
(这可能是规范中的错误,因为这个字节序列被定义为两个不同状态的结果)或0x20, 0x00
作为回报,但我没有看到任何方式api返回任何东西,我是对的吗?
我正在 Android Studio 中使用 gradle 进行开发。
我的 .gradle/daemon/ 占用高达 50GB 的空间。
它由大约 50 个大小在 1MB 到 3GB 之间的文件组成。
如何减小该文件夹的大小?如何安全地清理呢?
我正在关注好的回购,它展示了如何制作折叠工具栏WhatsApp-ProfileCollapsingToolbar的自定义行为.
我不喜欢的是当工具栏下方的图片(工具栏的字体为白色)为白色时,工具栏不可见.所以我试图将工具栏的背景设置为某种颜色.
首先我添加到widget_header_view.xml android:background="@android:color/holo_red_light"
,现在我喜欢它:
<?xml version="1.0" encoding="utf-8"?>
<com.anton46.whatsapp_profile.HeaderView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/holo_red_light"
android:orientation="vertical">
<TextView
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/activity_horizontal_margin"
android:ellipsize="end"
android:maxLines="1"
android:textColor="@android:color/white"
android:textSize="@dimen/header_view_start_text_size"
android:textStyle="bold" />
<TextView
android:id="@+id/last_seen"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:textColor="@android:color/white" />
</com.anton46.whatsapp_profile.HeaderView>
Run Code Online (Sandbox Code Playgroud)
而在activity_main.xml中我已经改变了app:contentScrim="?attr/colorPrimary"
对app:contentScrim="@android:color/holo_red_light"
但是因为这个repo在WhatsappHeaderBehavior中使用边距效果如下:
但我希望它像:
编辑1:
/sf/users/240532561/在/sf/answers/26071/80227/2401535中提出的带有填充的解决方案没有帮助,因为"浮动"工具栏覆盖了后退按钮,如下所示:
android android-layout android-toolbar android-collapsingtoolbarlayout android-layoutparams
android ×9
acra ×1
android-ble ×1
android-collapsingtoolbarlayout ×1
android-usb ×1
back-stack ×1
exception ×1
gatt ×1
geofencing ×1
gradle ×1
time ×1