2015年8月28日金曜日

MediaControllerのバグかもしれない

MediaControllerのバグかもしれない

  1. VideoViewを使って、横位置FullScreenで動画を再生させる。
  2. MediaControllerを使って、pauseを手動で行う。動画は停止状態になる。
  3. 端末を縦位置にする。configuration changeを発生させる。
  4. Logが真っ赤になる。

真っ赤に流れるボクのLogCat
同じことを2回行うと、端末が反応しなくなり、再起動が必要になる。

E/WindowManager﹕ android.view.WindowLeaked: Activity jp.androyer.playmp4.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{2210feb8 V.E..... R....... 0,0-1280,117} that was originally added here
            at android.view.ViewRootImpl.<init>(ViewRootImpl.java:370)
            at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:248)
            at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
            at android.widget.MediaController.show(MediaController.java:349)
            at android.widget.MediaController.show(MediaController.java:306)
            at android.widget.VideoView.toggleMediaControlsVisiblity(VideoView.java:697)
            at android.widget.VideoView.onTouchEvent(VideoView.java:638)
            at android.view.View.dispatchTouchEvent(View.java:7767)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2230)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1931)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2230)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1931)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2230)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1931)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2230)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1931)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2230)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1931)
            at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2072)
            at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1518)
            at android.app.Activity.dispatchTouchEvent(Activity.java:2531)
            at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2020)
            at android.view.View.dispatchPointerEvent(View.java:8004)
            at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4136)
            at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3990)
            at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3548)
            at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3598)
            at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3567)
            at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3674)
            at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3575)
            at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3731)
            at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3548)
            at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3598)
            at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3567)
            at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3575)
            at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3548)
            at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5817)
            at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5797)
            at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5768)
            at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:5897)
            at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185)
            at android.os.MessageQueue.nativePollOnce(Native Method)
            at android.os.MessageQueue.next(MessageQueue.java:138)
            at android.os.Looper.loop(Looper.java:131)
            at android.app.ActivityThread.main(ActivityThread.java:5257)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:788)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:604)
            at dalvik.system.NativeStart.main(Native Method)

解答は次のサイトにあった。
Android MediaPlayer with MediaController: LogCat error “Activity has leaked window that was originally added here”

onSaveInstanceState()やonCreate(Bundle savedInstanceState)による作り込みを完成させてから、こんな現象が発生することを知った。むむむ!

2015年8月18日火曜日

常駐考察メモ

常駐考察メモ

私の出荷済アプリにおいては、参照カウンターを設けて、これがゼロになると、データベースを閉じる&アプリ終了するという方法を採用していた。
しかしながら、下記エラーが発生するという報告が利用者から来た。

Caused by: java.lang.IllegalStateException: Cannot perform this operation because the connection pool has been closed.

上記エラーへの対応方法をネットで調べると、「データベースを閉じるな」という方法が提案されている。
onDestroy()においてデータベースclose()しているにも関わらず、上記エラーが発生しているという状況から察するに、このclose()の後で、onStartCommand()がメッセージを受け取っているということが推測させる。
もはや、どうすることもできません。

●データベースを管理する。
●外部から不意のメッセージを受け取る
この2個の条件を満足させるためには、常駐化しかないかも。

参考:NotificationListenerServiceを実装させたアプリでは、NotificationListenerServiceは常駐している。また、類似アプリの振る舞いを観察しても、常駐させている。

NotificationListenerServiceに関する実験メモ

NotificationListenerServiceに関する実験メモ

【1】bindについて
NotificationListenerServiceは、Serviceであるため、まさにそのとおりに使えるのではないかという仮説を立てて、
1.Activityとbindで結ぶ
2.データベースの管理
3.NotificationListenerServiceとしての本来機能
の3個を、この順番で、実行をさせてみた。
上位2個までは順に順調に実行が完了していった。
本体の「設定」>「通知へのアクセス」>本アプリの選択したあと、通知(Notification)を受け取るようにしてみたところ、次のようなエラーが出た。

W/Parcel﹕ **** enforceInterface() expected 'android.os.IMessenger' but read 'android.service.notification.INotificationListener' W/Binder﹕ Caught a RuntimeException from the binder stub implementation. java.lang.SecurityException: Binder invocation to an incorrect interface at android.os.Parcel.nativeEnforceInterface(Native Method) at android.os.Parcel.enforceInterface(Parcel.java:451) at android.os.IMessenger$Stub.onTransact(IMessenger.java:48) at android.os.Binder.execTransact(Binder.java:404) at dalvik.system.NativeStart.run(Native Method)

残念なことに、私には詳細を調べる能力や気力はありません。
NotificationListenerServiceは、本体設定>「通知へのアクセス」の設定が行われた直後に、本来機能として「何か」とbindします。
しかしながら、上記実験プログラムでは、NotificationListenerServiceは、一番最初にActivityとbindしてしまっているため、上記エラーが発生したものと推測します。

推測ですが、NotificationListenerServiceは、「Avtivityとのbind」との共存はできないのかもです。

【2】他のアプリからのIntent
他のアプリからIntentで、NotificationListenerServiceにアクセスしようとすると、クラッシュする。
6736-6736/jp.androyer.vivitovib E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: jp.androyer.vivitovib, PID: 6736
    java.lang.SecurityException: Not allowed to start service Intent { flg=0x20000000 cmp=jp.Androyer.NotificationLauncher/.NService (has extras) } without permission android.permission.BIND_NOTIFICATION_LISTENER_SERVICE
            at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1571)
            at android.app.ContextImpl.startService(ContextImpl.java:1548)
            at android.content.ContextWrapper.startService(ContextWrapper.java:495)
            at jp.androyer.vivitovib.Nippon$exportList.onPostExecute(Nippon.java:651)
            at jp.androyer.vivitovib.Nippon$exportList.onPostExecute(Nippon.java:638)
            at android.os.AsyncTask.finish(AsyncTask.java:632)
            at android.os.AsyncTask.access$600(AsyncTask.java:177)
            at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:645)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:149)
            at android.app.ActivityThread.main(ActivityThread.java:5257)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:788)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:604)
            at dalvik.system.NativeStart.main(Native Method)

クラッシュを引き起こさせるとは、とても思い罪を犯したということですね。

2015年7月27日月曜日

鳴り分け君1号

新作アプリを開発・公開しました。

通知の内容を基に、音楽や振動パターンを鳴り分けます。
無料ですのでお気軽にお使いください。

製品名:鳴り分け君1号
読み方:なりわけくんいちごう

https://play.google.com/store/apps/details?id=jp.Androyer.NotificationLauncher


その2
端末の振動パターンを編集できるアプリです。
編集後の振動パターンは拙作「鳴り分け君1号」で利活用することになります。
無料ですのでお気軽にお使いください。

製品名:びびっとバイブ
英語名:ViviToVib


2015年6月8日月曜日

Could not reserve enough space for object heap

以前下記のような趣旨のエラーが出たように記憶しており、その回避のために、Android Studio>File>Settings>Build Tools>Compiler>VM Options欄にheapサイズを大きくすべく -Xmx????m などと書いた。
しかしながら、また、下記のエラーが出た。今回は、VM Options欄を空欄にしてみた。そうすれば、エラーは無くなった。むむむ!

そして、その後また同様のエラーが発生した。
-Xmx512m と書くとエラーが無くなった。数値が大きければ良いというものでは無いらしい。

Error:Unable to start the daemon process.
This problem might be caused by incorrect configuration of the daemon.
For example, an unrecognized jvm option is used.
Please refer to the user guide chapter on the daemon at http://gradle.org/docs/2.2.1/userguide/gradle_daemon.html
Please read the following process output to find out more:
-----------------------
Error occurred during initialization of VM
Could not reserve enough space for object heap
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.


その後、Android Studioが1.3になると、VM Options欄が消失していた。いままでの苦労はなんだったんだろうか。

2015/08/08 また出てしまった。
Error:Unable to start the daemon process: could not reserve enough space for object heap.
Please assign more memory to Gradle in the project's gradle.properties file.
For example, the following line, in the gradle.properties file, sets the maximum Java heap size to 1,024 MB:
Windowsを再起動したり、Android Studioを再起動したりすると、このエラーは消える。むむむ!

2015/08/13 また出てしまった。Android Studio 1.3.1
Error:Unable to start the daemon process: could not reserve enough space for object heap.
Please assign more memory to Gradle in the project's gradle.properties file.
For example, the following line, in the gradle.properties file, sets the maximum Java heap size to 1,024 MB:
org.gradle.jvmargs=-Xmx1024m

2015/08/27 また同じのが出てしまった。Android Studio 1.3.2
Error:Unable to start the daemon process: could not reserve enough space for object heap.
Please assign more memory to Gradle in the project's gradle.properties file.
For example, the following line, in the gradle.properties file, sets the maximum Java heap size to 1,024 MB:
org.gradle.jvmargs=-Xmx1024m
Windowsを再起動すれば直るため、このエラーメッセージの内容は参考程度ですね。

2016/01/05 Android Studio 1.5.1
この問題は、Android Studio の問題では無く、Windowsが発生させているようです。
上記のように、オプション欄にいろいろ数値を代入していじくっても解決しません。
よく発生するのは、Windowsのシステムアップデートの時です。事前に、Windowsのシステムアップデートをしっかり定着させておきましょう。
それでも、本日は、頻繁に発生してしまいました。Windowsのいわゆる「起動マネージャ」を使い、Windowsの起動時に起動されてしまうアプリを見直してみましょう。私の場合、この確認行為をしただけで、実際には何も変更を加えていないにも関わらず、Android studioの問題が消失しました。むむむ。

2015年5月17日日曜日

新作アプリ公開:御起動様

新作アプリ公開:御起動様

Androidのアプリを作成・公開しました。
「他のアプリを、指定した時間に起動させる」アプリです。
ゲームアプリを朝に起動させて、ゲーム音楽で目覚めるっていう使い方ができます。
無料ですので、気軽にお使いください。
アプリ名:御起動様
読み方:ごきどうさま

https://play.google.com/store/apps/details?id=jp.Androyer.goKeyDo

2015年4月30日木曜日

CheckBoxの再利用

CheckBoxの再利用

CheckBoxを作成&使用して、その後、そのオブジェクトを再利用したい場合があるかもしれない。
2回目の使用時にも、setCheckedメソッドを使ってチェックを付けるのである。

このsetCheckedメソッドであるが、setOnCheckedChangeListenerメソッドを実行してしまった後で、setCheckedメソッドを実行すると、onCheckedChangedメソッドが呼ばれてしまう。
2回目の使用時に、そうなってしまった場合、不都合が生じる場合が有る。

Windowsにおいても、似た仕掛けがあるが、Windowsの場合には、onCheckedChangedメソッドに「端末利用者がチェックを施したのか」「プログラムでチェックを施したのか」がわかる引数が付いている。
Androidの場合には、そういう引数は無い。

このため、setCheckedメソッドを実行する直前に、setOnCheckedChangeListener(null)を実行させれば良い。setCheckedメソッドを実行させた後で、setOnCheckedChangeListenerを再設定し直せば良い。