Skip to content

Instantly share code, notes, and snippets.

Avatar

Ali Asadi AliAsadi

View GitHub Profile
View notification.java
new Notification.Builder(context)
.setContentTitle(title)
.setContentText(contentText)
.setSmallIcon(R.drawable.icon)
.setContentIntent(intent);
View longArrayToString.java
private static String longArrayToString(long[] values) {
StringBuffer sb = new StringBuffer();
if (values != null) {
for (int i = 0; i < values.length - 1; i++) {
sb.append(values[i]).append(DELIMITER);
}
sb.append(values[values.length - 1]);
}
return sb.toString();
}
View notificationOreo.java
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(CHANNEL_ID, "Default", NotificationManager.IMPORTANCE_DEFAULT);
channel.setVibrationPattern(new long[0]);
channel.enableVibration(false);
channel.setSound(null,null);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
if (notificationManager != null) {
notificationManager.createNotificationChannel(channel);
}
}
View setVibrationPattern.java
if (vibrationPattern !=null && vibrationPattern.lenght > 0){
this.mVibrationEnabled = true;
this.mVibration = vibrationPattern
}else{
this.mVibrationEnabled = false;
this.mVibration = null;
}
View SingletonManager.java
public class SingletonManager {
private static SingletonManager singleton;
private Context context;
private SingletonManager(Context context) {
this.context = context;
}
public synchronized static SingletonManager getInstance(Context context) {
View getApplicationContext.java
SingletonManager.getInstance(getApplicationContext());
View SingletonManager.Java
public class SingletonManager {
// ....
public synchronized static SingletonManager getInstance(Context context) {
if (singleton == null) {
singleton = new SingletonManager(context.getApplicationContext());
}
return singleton;
}
}
View LoginActivity.java
public class LoginActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
//...
SingletonManager.getInstance(this);
}
}
View LoginActivityLocation.java
public class LoginActivity extends Activity implements LocationListener {
@Override
public void onLocationUpdated(Location location){
// do something
}
@Override
protected void onStart(){
LocationManager.getInstance().register(this);
View ActivityOnDestroy.java
protected void onDestroy() {
unregisterReceivers();
LocationManager.getInstance().unregister(this);
AppState.getInstance().setStateChangeListener(null);
LocalBroadcastManager.getInstance(getApplicationContext())
.unregisterReceiver(messageReciver);
super.onDestroy();
}