小编mal*_*ita的帖子

从onPause中的片段中删除位置更新时内存泄漏

在我的应用程序中的一个片段中,我需要位置更新,以确定用户何时接近一个简短的位置列表,以便用户可以获得相关信息.当我在onConnected()回调中使用创建位置更新请求时

LocationServices.FusedLocationApi.requestLocationUpdates(client, LocationRequest.create(), this);
Run Code Online (Sandbox Code Playgroud)

我还使用了删除onPause()方法中的更新

LocationServices.FusedLocationApi.removeLocationUpdates(client, this);
Run Code Online (Sandbox Code Playgroud)

然而,即使我调用该方法来删除位置更新,我也会从泄漏金丝雀那里得到警告,每当我离开该片段时,我的片段就会被泄露(所有片段导航都是使用replace()事务完成的).我在我的片段中启动位置请求时做错了什么,或者我没有在onPause()中正确清理请求,对此的任何帮助将不胜感激.

这是我的片段类的简化模型中的代码

public class BlankFragment extends Fragment implements GoogleApiClient.ConnectionCallbacks
    , GoogleApiClient.OnConnectionFailedListener, LocationListener {

private GoogleApiClient client;
private TextView textView;

public BlankFragment() {
    // Required empty public constructor
}


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View root = inflater.inflate(R.layout.fragment_blank, container, false);
    textView = (TextView) root.findViewById(R.id.location);
    client = new GoogleApiClient.Builder(getContext())
            .addApi(LocationServices.API)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .build();
    return root;
}

@Override
public void onConnected(@Nullable Bundle bundle) {
    startLocationUpdates();
}

private void startLocationUpdates() {
    if …
Run Code Online (Sandbox Code Playgroud)

android android-fragments google-play-services fusedlocationproviderapi leakcanary

3
推荐指数
1
解决办法
1223
查看次数

在BottomNavigationView上为选定的图标设置动画

我正在寻找我目前在我的底形游览视图中使用的Vectordrawablawables,当为猫头鹰应用程序的本材料产品学习时选择了一个选项卡时。但是,与工具栏视图不同,当我使用 MenuItem.getIcon() 获取图标时,将其转换为 AnimatedVectorDrawable 并调用 animate() 方法,没有动画。

我想知道我是否可以做些什么来实现这一点,这是否可能包含在稳定的 Material Components 库中,或者我是否最好创建一个扩展 BottomNavigationView 类的自定义视图。

android material-design bottomnavigationview material-components material-components-android

1
推荐指数
1
解决办法
3060
查看次数