小编Ahm*_*dli的帖子

Android - 将@IntDef值放在@interface中可以吗?

我正在尝试@IntDef在Android开发中实现注释.

第一种方法:在Constant.java类中分隔定义看起来很棒:

public class Constant {
   @IntDef(value={SORT_PRICE, SORT_TIME, SORT_DURATION})
   @Retention(RetentionPolicy.SOURCE)
   public @interface SortType{}
   public static final int SORT_PRICE = 0;
   public static final int SORT_TIME = 1;
   public static final int SORT_DURATION = 2;
}
Run Code Online (Sandbox Code Playgroud)

用法:

@Constant.SortType int sortType = Constant.SORT_PRICE;
Run Code Online (Sandbox Code Playgroud)

但是当在一个文件中存在多个定义(例如UserType,StoreType等)时,事情会变得更加混乱.

第二种方法:所以我想出了这样的东西来分隔定义之间的值:

public class Constant {
   @IntDef(value={SortType.SORT_PRICE, SortType.SORT_TIME, SortType.SORT_DURATION})
   @Retention(RetentionPolicy.SOURCE)
   public @interface SortTypeDef{}

   public static class SortType{
       public static final int PRICE = 0;
       public static final int TIME = 1;
       public static …
Run Code Online (Sandbox Code Playgroud)

java android annotations

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

Android - 如何恢复ViewPager项目的状态

我在恢复View内部状态方面遇到了麻烦ViewPager.该内容ViewPager是一个视图扩展FrameLayout.

问题是FrameLayout.onRestoreInstanceState()如果以编程方式添加到中,则不会被调用ViewPager

这是我的代码 Activity.java

private ViewPager vPager;
private MainPagerAdapter mAdapter;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    setContentView(R.layout.activity_layout);
    // all the findViewById stuff

    CustomView cv1 = new CustomView(this);
    CustomView cv2 = new CustomView(this);

    cv1.setId(R.id.custom_view_id_1);
    cv2.setId(R.id.custom_view_id_2);

    mAdapter = MainPagerAdapter();
    mAdapter.addView(cv1);
    mAdapter.addView(cv2);
    vPager.setAdapter(mAdapter);
}
Run Code Online (Sandbox Code Playgroud)

MainPagerAdapter是一个来自这个问题的接受答案的课程

的源代码 CustomView.java

@Override
protected Parcelable onSaveInstanceState() {
    Log.d(TAG, "onSaveInstanceState() called");
}

@Override
protected void onRestoreInstanceState(Parcelable state) {
    Log.d(TAG, "onRestoreInstanceState() called");
}
Run Code Online (Sandbox Code Playgroud)

到目前为止,这是我的发现:

  1. onSaveInstanceState() …

java android

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

在弹性 beantalk 部署之间维护 OAuth 密钥

我有一个在 AWS Elastic Beanstalk 环境中运行的 laravel 应用程序。我使用 Laravel Passport 来处理身份验证。

每次运行时eb deploy,密钥都会被删除,因为它不是版本控制文件的一部分(包含在 .gitignore 中)。因此,我必须php artisan passport:keys在 EC2 实例中手动运行以生成密钥。但这将使所有用户都需要再次登录,因为旧令牌现在无效,因为它是新密钥对。

为我的配置提供一致的 oauth-public 和 oauth-private 密钥的最佳实践是什么?

我正在考虑将密钥包含在存储库中,但我认为不建议这样做。

另一种方法是我生成一次密钥,然后将其上传到 S3。然后有一个部署后脚本来检索 S3。

有没有更好的办法?

amazon-elastic-beanstalk laravel-5 laravel-passport

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