6
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【Android】NavigationのSafe Argsを使うときの注意点

Posted at

JetpackのNavigationは画面遷移を手軽に書けて非常に便利です。

中でもargumentsを型安全に取り扱えるSafe Argsはとても重宝します。

ただし、Safe Argsに入れるのがintやStringではなく自作クラスの場合は注意が必要です。

Safe Argsで自作クラスを使う場合

クラスがParcelableSerializableならばSafe Argsに含めることができます(Safe ArgsはBundleのラッパーであるため)。自作クラスと書きましたが、自作でもライブラリのクラスでも同じです。

開発時はそれで普通に使えるかと思いますが、Releaseビルドにした途端に

android.view.InflateException: Binary XML file line #33: Binary XML file line #33: Error inflating class fragment

といったようなエラーが発生したりします。

proguardに追加

Releaseビルドで発生することから想像できるとおり、proguardに記述が必要です。

com.example.hoge.StatusクラスをSafe Argsで使用するならば

-keepnames class com.example.hoge.Status

としてクラス名が難読化されないようにする必要があります。

6
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?