Category: Android Application
Android application, Mobile Android, Mobile Application
ปกติเวลาเราต้องการโหลดข้อมูลจากเซิร์ฟเวอร์ เราจะสร้างการเชื่อมต่อแบบ AsyncTask ไว้ใน Activity class or Fragment class เช่น จากตัวอย่าง url ที่ส่งเข้ามาจาก getDataFromServer() จะนำมาใช้ที่ protected String doInBackground ในที่นี้คือ params[0] สมมติว่าโค้ดมันยาวเราอยากจะย้าย AsyncTask ออกไปจาก Activity or Fragment เราก็ไปสร้าง class ไฟล์ใหม่ได้ เช่น New->Java Class-> LoadData.java ดังตัวอย่าง...
ใช้ Android Studio สร้าง APK file แล้วเกิด Error messages ประมาณ “Caused by: java.lang.ClassNotFoundException: com.android.tools.lint.client.api.Vendor” โดยมี Error ฉบับเต็มประมาณนี้ Could not load custom lint check jar file /Users/tonyrich/.gradle/caches/transforms-3/c200ac22d419ea2f987b972fa499a113/transformed/jetified-startup-runtime-1.1.1/jars/lint.jarjava.lang.NoClassDefFoundError: com/android/tools/lint/client/api/Vendorat androidx.startup.lint.StartupRuntimeIssueRegistry.(StartupRuntimeIssueRegistry.kt:37)at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)at java.base/java.lang.Class.newInstance(Class.java:584)at...
ปัจจุบันตอนนี้ Android 12 (API version 31 and above) ออกมาใช้งานจริงแล้ว เมื่อเราทำการอัพเดท Android App โดยการกำหนด “targetSdkVersion” = 31 และปรับค่า compileSdkVersion = 31 แล้วทดลองรันโปรแกรม ปรากฎว่าเกิด error message ดังนี้ The application could not be installed: INSTALL_PARSE_FAILED_MANIFEST_MALFORMED Installation failed...
หลังจากกำหนด targetSdkVersion 30 ปรากฎว่าแอปปลิเคชันเปิดแล้วปิดตัวทันที ลองไปตรวจสอบใน Logcat พบว่ามีเพียงข้อความ error A/libc: fdsan: attempted to close file descriptor 86, expected to be unowned แต่พอเปลี่ยน targetSdkVersion 29 กลับสามารถทำงานได้ปกติ เลยสืบค้นจนพบว่า Error ที่เกิดขึ้น นั่นเกี่ยวกับการใช้ <pl.droidsonroids.gif.GifTextView android:layout_width=”match_parent” android:layout_height=”match_parent” android:background=”@drawable/image” /> พบว่าถ้ารูปภาพที่โหลดไม่ใช่...
วันนี้เรามีอีกวิธีในการตรวจสอบว่าแอปฯของเราอยู่ในสถานะทำงานอยู่ (foreground) หรือถูกปิดหรือย่อให้อยู่เบื้องหลัง (Background) โดยวิธีนี้เราจะเรียกใช้ Lifecycle Observer ที่มากับ androidx (androidx.lifecycle.OnLifecycleEvent) ตรวจจับการทำงานของ Event ของแอปฯ การเรียกใช้เราประกาศครั้งเดียวตอนเปิดแอปฯ แล้วตัว lifecycle จะคอยจับ event ให้เรา ดังนี้ public class MainApp extends AppCompatActivity implements LifecycleObserver { … @Override protected void onCreate(Bundle savedInstanceState)...
เคยประสบปัญหาโดน Google Rejected App ด้วยเหตุผลว่า “Violation of Interfering with Apps, Third-party Ads, or Device Functionality policy” หรือ แบบง่ายๆคือ การแสดงโฆษณาขึ้นมาหลังจากที่ปิดแอปฯ หรือย่อแอปฯ หรือภายนอกแอปฯ นั่นเอง ซึ่งจากที่ทดสอบมา สมมติว่าขณะที่แอปกำลังโหลดโฆษณา (Interstitial Ads) อยู่แล้วเราทำการกดปุ่ม Home เพื่อย่อแอปฯไปเบื้องหลัง ซึ่งในความเป็นจริงแล้วแอปฯ ก็ยังทำงานอยู่ในเบื้องหลัง (Background) นั่นเอง เพราะฉะนั้นเมื่อโหลดโฆษณาเสร็จ...