Programing

출시 전 Android 애플리케이션 최적화

lottogame 2020. 7. 14. 08:19
반응형

출시 전 Android 애플리케이션 최적화


내 프로그램의 효율성대해 " 특별한 "상황에 있습니다 . 이제는 응용 프로그램의 성능을 개선하고 배터리 소비를 줄여야하는 단계에 있습니다.

질문하기 전에 :

이제 다른 개발자 가 자신의 응용 프로그램을 최적화하는 데 사용한 특수 수정 프로그램 에 대해 알고 싶습니다 . 사용자가 인식하지 못하거나주의를 기울이지 않는 물건. 그러나이 수정은 배터리 수명을 늘리거나 응용 프로그램의 유지 관리를 개선하는 데 도움이됩니다.

그렇다면 귀하의 독특한 최적화 트릭은 무엇입니까?

나는 실제로 지식을 찾고있는 특별한 상황에 처해 있으며 이것이 개발자들 모두 자신이 처한 상황에 대한 지식을 공유 할 수있는 좋은 기회라고 생각합니다.

훌륭한 개발자가 자신의 지식을 공유하도록 장려하는 훌륭한 답변에 투표하십시오.


어떤 시점에서 알려진 트릭을 사용하면 한계에 도달 할 수 있습니다. 이 시점에서 가장 좋은 방법은 코드를 프로파일 링하고 특정 요구 사항에 따라 병목 현상이 발생한 영역을 확인하는 것입니다.

MATTraceview를 사용하여 RAM 사용 조사 : 도구를 사용하여 응용 프로그램을 프로파일 링하는 방법에 대한 기사입니다.


할당 및 추적 스쿼시. 할당량이 많을수록 가비지 수집기가 더 자주 실행되어 프로세스가 100ms 정도의 비교적 오랜 시간 동안 다른 작업을 수행하지 못하게됩니다.

내가 아는 가장 좋은 도구는 DDMS에 포함 된 할당 추적기 입니다.

GC는 사용자 경험에 영향을 줄뿐만 아니라 불필요한 할당과 GC는 일부 컴퓨팅 리소스를 소비합니다.

다음은 예제와 작은 요령입니다. 내 응용 프로그램에는 10 분의 초를 포함하여 현재 (오디오) 시간을 보여주는 시계가 있습니다. 이것은 자주 업데이트됩니다. 그리고 TextView 는 CharSequence로 setText ()를 호출 할 때마다 내부적으로 할당을 수행합니다 . 그러나 setText (char [] text, int start, int len) 변형을 사용하여 아무것도 할당하지 않습니다. 이것은 문서화되어 있지 않으며 내가 물었을 때 아무도 대답하지 않았습니다.

이런 것들이 많이 있습니다. 그리고 이것이 내 앱에 50 % 원시 코드가 포함 된 이유 중 하나입니다 (그러나 다른 이유도 있습니다).

이 외에도 ProGuard 를 사용해 보는 것이 좋습니다 . 여러 최적화 단계를 수행하고 해당 정보를 프로젝트 내에서 사용되지 않은 메소드로 기록하므로 코드에서 남은 부분을 제거하는 데 도움이됩니다.


앱의 화면 시간이 길어 지면 가능한 한 검은 색을 사용하십시오 . 이렇게하면 장치의 최악 부분 인 화면, 특히 AMOLED 전화 및 태블릿의 배터리 소비가 줄어 듭니다.


여러 활동이있는 응용 프로그램의 경우 적절한 Intent 플래그를 사용하여 전면으로 가져와야하는 활동을 다시 시작하지 않는지 확인하십시오. 힙이 제어되고 불필요한보기, 바인딩 및 컨텍스트가 작성되지 않는지 확인하십시오.

앱이 실행될 때 이러한 모든 것을 보여주는 가장 좋은 도구는 다음과 같습니다.

adb shell dumpsys meminfo 'your apps package name'

SQLlite를 사용할 때는 인덱스에 특별한주의를 기울이십시오. 아무 것도 가정하지 마십시오. 검색에 일반적으로 사용되는 열에 색인을 넣을 때 Zwitscher에서 엄청난 속도 향상을 얻었습니다.


UI 측면에서 앱을 최적화하는 데 도움이되는 몇 가지 팁 :

  • 사용 convertView목록 어댑터 - 새 뷰 내부를 작성하는 경우는 매우 비싼 것 Adapter.getView()이 루틴이 목록의 모든 위치를 호출한다. 사용 convertView하면 이미 생성 된보기를 재사용 할 수 있습니다. ApiDemosViewHolder 에서 좋은 예제를 함께 사용할 수 있습니다 .

  • 레이아웃이 완전히 최적화되지 않고 향상 될 수 있습니다 (예 : 병합 또는 부모 제거). Android 도구 layoutopt 는 이러한 상황을 찾아냅니다. 개별 뷰를 검사하기 위해 HierarchyViewer와 함께 사용할 수 있습니다. 자세한 내용은 여기를 참조하십시오 .

  • 백그라운드 드로어 블 제거- 어떤 뷰를 그려야 하는지를 감지 하는 데 문제 가있는 Android 프레임 워크 (아직 가지고 있습니까?) (기본) 배경 드로어 블은 나중에 불투명 한 UI에 의해 숨겨 지도록 그려 질 가능성이 있습니다. 이 낭비적인 그림을 없애려면 단순히 배경 그리기를 제거하십시오.

사용자 정의 스타일을 사용하여 수행 할 수 있습니다

<resources>
    <style name="Theme.NoBackground" parent="android:Theme">
        <item name="android:windowBackground">@null</item>
    </style>
</resources>

배터리 사용 측면에서 앱을 최적화하는 데 도움이되는 몇 가지 팁 :

  • 네트워킹 유형을 확인하고 사용자가 Wi-Fi 또는 3G로 로밍하지 않는 지역에 도착할 때까지 기다린 다음 연결을 사용하도록 허용

  • 가능하면 텍스트 데이터에 gzip을 사용하여 다운로드 및 구문 분석 속도를 높입니다.

  • XmlPullParserFactory/ BitmapFactory/ StringBuilder/ Matcher등의 복잡한 Java 객체를 재활용하십시오 .

For more battery tricks see Coding for Life - Battery Life, That Is.


Something to think about: DO NOT overuse String, for example in a huge loop. This will create a lot of String objects that have to be GC'ed. The "Bad coding" example will produce 2 string objects every loop. Next example will produce only one final String and a single stringbuilder. This makes a huge difference when optimizing huge loops for speed. I used stringbuilder a lot when making my Wordlist Pro Android app, and it got really speedy when going through 270000 words in no time.

    //Bad coding:
    String s = "";
    for(int i=0;i<999999;i++){
        s = "Number=";
        s = s + i;
        System.out.println(s);
    }

    //Better coding
    final String txt = "Number=";
    StringBuilder sb = new StringBuilder();
    for(int i=0;i < 999999;i++){
        sb.setLength(0);
        sb.append(txt);
        sb.append(i);
        System.out.println(sb);
    }

I wrote a more extended blogpost about the matter. read here


I guess using "final" variables everywhere where it's possible could also improve execution speed.


Optimize your PNG pictures with tools like OptiPNG and PNGCrush to shave off some (kilo)bytes from APK size. Image optimization tips for websites apply here too: use appropriate picture formats, play with JPG compression, consider using binary transparencies instead of 8-bit transparencies etc.

If you ship big PNGs with alpha channel, you can trade some APK size for startup speed and use separate JPGs for RGB and A channels.

If you're making HTTP connections, check that your HTTP client utilizes content compression. If it caches received HTTP responses, check that it understands and uses caching-related HTTP headers correctly.


If you have network operations try re-using same httpclient instance. Avoid using regular expressions.


Try using DDMS to track all the threads running in the system. For example i have noticed that I was using webview to display html content, i noticed that it creates few threads for cookie management session management etc..which increased my memory foot print. So unless you have a serious need for displaying complex html try using normal utility class "Html" in android to display html content. This might be useful for people who are displaying Eula since eula typicall contains html text.

If you have to do network operations try using AndroidHttpClient if you are beginner, it has got some good capabilities for Caching SSL sessions and all it really helps in improving your performance. Always set your socket connection timeouts to something around 60 seconds or some finite values because infinite timeouts can cause deadlocks especially if you drop your connection during ssl handshake.


Use the Android Resource Tracker to find unused resources in your project that can be deleted.


Avoid using XPath if you can parse your XML input by using string manipulation routines to get the text between the tags. I have tested and can confirm a 10x improvement in this case, on a 50000 items data set, on a HTC Desire.


I know I am joining a bit later to this conversation but it would be perfect to have a lot of good tips in one place, so I hope this thread will be alive and updated pretty often. My tips:

  • Don't block UI thread with expensive jobs, user will leave if there is no response from app (use AsyncThreads).
  • Use the LINT, new tool which scans Android project sources for potential bugs.

..will be updated..

참고URL : https://stackoverflow.com/questions/5626947/optimising-android-application-before-release

반응형