안 드 로 이 드 교육 학습 수기
훈련 문서:http://developer.android.com/training/index.html
- implicit intent 를 통 해 구체 적 인 Intent. ACTION 을 설정 하여 다른 app 을 열 때 해당 하 는 activity 가 열 릴 수 있 는 지 여 부 를 판단 해 야 합 니 다. 그렇지 않 으 면 crash 가 발생 합 니 다.
두 가지 방법, 첫 번 째 상세 한 조회, 두 번 째 는 비교적 간단 하 다.
PackageManager packageManager =
getPackageManager()
; List activities = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); boolean isIntentSafe = activities.size() > 0;
——————————————————————————————————————————————————————————————————if (intent.resolveActivity(getPackageManager()) != null)
- private void share(String content, Uri uri){
- Intent shareIntent = new Intent(Intent.ACTION_SEND);
- if(uri!=null){
- shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
- shareIntent.setType("image/*");
- //当用户选择短信时使用sms_body取得文字
- shareIntent.putExtra("sms_body", content);
- }else{
- shareIntent.setType("text/plain");
- }
- shareIntent.putExtra(Intent.EXTRA_TEXT, content);
- //自定义选择框的标题
- //startActivity(Intent.createChooser(shareIntent, "邀请好友"));
- //系统默认标题
- startActivity(shareIntent);
- }
If a feature is not a core part of your app's functionality, you should consider handing the work over to another app
-判断网络是否通畅:
ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connMgr.getActiveNetworkInfo(); if (networkInfo != null && networkInfo.isConnected())...
android:startColor="#ff8c00"
android:endColor="#FFFFFF"
android:angle="270" />
android:width="2dp"
android:color="#dcdcdc" />
android:radius="2dp" />
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
shape>
-Use android:animateLayoutChanges="true" to animate when the layout changes. animateLayoutChanges 를 사용 하여 layot 변동 을 제어 할 때 애니메이션 효과 가 발생 합 니 다.
your app should not add a Back button to the UI.
When launching another application's activity to allow the user to say, compose an email or pick a photo attachment, you generally don't want the user to return to this activity if they relaunch your application from the Launcher (the device home screen). It would be confusing if touching your application icon brought the user to a "compose email"screen. 다른 app 의 activity 를 시작 할 때, 예 를 들 어 메 일 을 쓰 거나 그림 첨부 파일 을 추가 하려 면, 일반적으로 사용자 가 launcher 에서 app 을 다시 시작 하 는 것 을 원 하지 않 을 때, 이 제3자 app 의 activity 로 돌아 갑 니 다.아이콘 을 누 르 면 메 일 창 으로 돌아 가면 사용자 가 곤 혹 스 러 울 수 있 습 니 다.
To prevent this from occurring, simply add theFLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET
flag to the intent used to launch the external activity, like so: 이러한 일 을 방지 하기 위해 lauch 제3자 activity 에 intent 에 flag 를 추가 하면 됩 니 다.Intent externalActivityIntent = new Intent(Intent.ACTION_PICK); externalActivityIntent.setType("image/*"); externalActivityIntent.addFlags( Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); startActivity(externalActivityIntent);
- searchView 를 추가 하 는 방법:
To add aSearchView
widget to the app bar, create a file namedres/menu/options_menu.xml
in your project and add the following code to the filexml version="1.0" encoding="utf-8"?>
-you can declare the logical parent of each activity by specifying theandroid:parentActivityName
attribute in theelement.
manifest 파일 에서 activity 의 'android: parentActivity Name' 속성 을 지정 하여 논리 적 인 부모 Activity 를 지정 합 니 다.(actionbar 의 위로 동작 을 실현 합 니 다.)
AlarmManager 는 app 수명 주기 외 에 시간 기반 작업 을 수행 할 수 있 습 니 다.예 를 들 어 alarm 으로 장기 적 으로 실행 되 는 작업 을 초기 화 합 니 다. 예 를 들 어 매일 service 를 켜 서 일기 예 보 를 다운로드 합 니 다."during" the life time of your application 을 확인 할 수 있 는 timing operations.Handler 와 Time, Thread 를 결합 하면 안 드 로 이 드 시스템 이 시스템 자원 을 더욱 잘 제어 할 수 있 습 니 다.
Generally speaking, avoid creating short-term temporary objects if you can. Fewer objects created mean less-frequent garbage collection, which has a direct impact on user experience. 가능 하 다 면 단기 대상 을 만 들 지 마 세 요.대상 이 적 을 수록 GC 의 빈도 가 낮 다 는 의미 다.
If you don't need to access an object's fields, make your method static. Invocations will be about 15%-20% faster.
방문 대상 의 구성원 이 필요 없다 면, 방법 을 static 로 쓰 세 요.호출 속도 20% 증가
It is a bad idea on Android. Virtual method calls are expensive, much more so than instance field lookups. It's reasonable to follow common object-oriented programming practices and have getters and setters in the public interface, but within a class you should always access fields directly.
인터페이스 에서 getter 와 setter 호출 을 사용 하 는 것 은 흔히 볼 수 있 는 대상 을 대상 으로 하 는 습관 이다.그러나 클래스 내부 에 서 는 get 방법 을 사용 하지 않 고 변 수 를 직접 방문 해 야 합 니 다.
activities should do as little as possible to set up in key life-cycle methods such as onCreate() andonResume()
activity 는 관건 적 인 생명주기 방법 (예 를 들 어 onCreate 나 onResume) 에서 가능 한 한 적은 일 을 해 야 한다.
The most effective way to create a worker thread for longer operations is with the AsyncTask class.
가장 효과 적 인 방법 은 asynctask 클래스 를 작성 하 는 것 입 니 다.
Although it's more complicated than AsyncTask, you might want to instead create your own Thread orHandlerThread class. If you do, you should set the thread priority to "background" priority by callingProcess.setThreadPriority() and passing THREAD_PRIORITY_BACKGROUND. If you don't set the thread to a lower priority this way, then the thread could still slow down your app because it operates at the same priority as the UI thread by default.
AsyncTask 보다 복잡 하지만 thread 나 handlerThread 를 쓰 고 싶 을 수도 있 습 니 다. 그러면 스 레 드 의 우선 순 위 를 설정 해 야 합 니 다.Process. setThreadPriority () 방법 을 사용 하여 매개 변 수 를 THREAD 에 전달 합 니 다.PRIORITY_BACKGROUND. 낮은 우선 순 위 를 설정 하지 않 으 면 이 thread 는 기본적으로 UI 스 레 드 와 우선 순위 이기 때문에 app 의 속 도 를 늦 출 수 있 습 니 다.
[메모리 유출 에 관 한 글]
http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2015/1225/3800.html
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.