-
tránh tạo các đối tượng không cần thiết
-
sử dụng string buffer (multi thread) hoặc string builder cho việc append chiều chuỗi string
-
hai mảng a[] b[] tốt hơn so với (a,b)
-
Nếu bạn không cần truy xuất vào các biến của object. Có thể làm cho phương thức của bạn thành static. Lúc đó việc gọi hàm sẽ nhanh hơn khoảng 15-20%. Việc này cũng có một lợi thế nữa là method của bạn khi được gọi cũng không làm ảnh hưởng đến object
-
Use Static Final For Constants, const int BIT BETTER than enum
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SyncService extends IntentService { | |
public static final String TASK_KEY = ""; | |
public static final int SYNC_CONTACT = 2; | |
public static final int SYNC_HISTORY = 1; | |
public static final int SYNC_GROUP = 0; | |
public SyncService() { | |
super(null); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MainActivity extends AppCompatActivity { | |
private CountingIdlingResource idlingResource = new CountingIdlingResource("aaaaa"); | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
final AlertDialog.Builder builder = new AlertDialog.Builder(this); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* for send object between fragment, activity, service... | |
* REMEMBER: dispose if not in use to avoid leak memory | |
*/ | |
public class RxBus<T> { | |
private static final String PREFIX = "$^%)@"; | |
private static RxBus instance; | |
private PublishSubject<BusMessage<T>> subject = PublishSubject.create(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<RadioGroup | |
android:orientation="horizontal" | |
android:id="@+id/radio_group" | |
android:layout_width="match_parent" | |
android:checkedButton="@+id/bt1" | |
android:layout_height="wrap_content"> | |
<RadioButton | |
android:id="@+id/bt1" | |
android:background="@drawable/toggle_bg" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// search text timer | |
mEdittext = (EditText) findViewById(R.id.editText); | |
subTextChange = new Subscriber<CharSequence>() { | |
@Override | |
public void onCompleted() { | |
Log.d(TAG, "onCompleted: "); | |
} | |
@Override | |
public void onError(Throwable e) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Observable<CharSequence> observable2 = Observable.create(new Observable.OnSubscribe<CharSequence>() { | |
@Override | |
public void call(final Subscriber<? super CharSequence> subscriber) { | |
txt2.addTextChangedListener(new TextWatcher() { | |
@Override | |
public void beforeTextChanged(CharSequence s, int start, int count, int after) { | |
} | |
@Override | |
public void onTextChanged(CharSequence s, int start, int before, int count) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.hungvu.testpack; | |
import rx.Observable; | |
import rx.Subscriber; | |
import rx.Subscription; | |
import rx.functions.Func1; | |
import rx.subjects.PublishSubject; | |
import rx.subjects.Subject; | |
/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// sample 3 UI event | |
mButton = (Button) findViewById(R.id.button); | |
Observable<View> clickEventObservable = Observable.create(new Observable.OnSubscribe<View>() { | |
@Override | |
public void call(final Subscriber<? super View> subscriber) { | |
mButton.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
subscriber.onNext(v); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// sample 2 asynchronous task | |
Observable<String> jsonTask = Observable.create(new Observable.OnSubscribe<String>() { | |
@Override | |
public void call(Subscriber<? super String> subscriber) { | |
subscriber.onNext(getJsonFromInternet()); | |
subscriber.onCompleted(); | |
} | |
}).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()); | |
// SUBCRIBE |