Hi i'm building app similar to Chathead. My service is checking if other app is in foregnound and if yes service hide chathead(ImageView move out of linearlayout and linarlayout is untouchable). Problem is, that after few hours running app, when service is checking which app is in foregnound and after want to hide chathead, layoutParams of Chatchead returning NullPointerException. Forexample app stop working when you wake up mobile after night.
Setting mMainIconLayoutParams
mMainIconLayoutParams = new WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_PHONE,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
| WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR,
PixelFormat.TRANSLUCENT);
mMainIconLayoutParams.gravity = Gravity.TOP | Gravity.LEFT;
mMainIconLayoutParams.x = 0;
mMainIconLayoutParams.y = 100;
mWindowManager.addView(mainIconlinearlayout, mMainIconLayoutParams);
Layout of Chathead:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="@+id/main_icon_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="false" />
</LinearLayout>
mMainIconLayoutParams.x retuning null...
case ANIMATION_HIDE:
if (mMainIconLayoutParams.x>(mDisplayWidth/2)) {
isMainIconStopped = true;
animationMainIcon = AnimationUtils.loadAnimation(this,
R.anim.move_from_center_to_right);
}
else
{.....}
Logcat:
java.lang.NullPointerException
at cz.lala.shortapp.service.Windowservice.moveMainIcon(Windowservice.java:373)
at cz.lala.shortapp.service.Windowservice.access$14(Windowservice.java:355)
at cz.lala.shortapp.service.Windowservice$1$1.run(Windowservice.java:204)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5153)
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:732)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:566)
at dalvik.system.NativeStart.main(Native Method)
My opinion is that this problem cause Android. Bescause app works fine and problem starts after few hours. Any idea to solve this problem?