Skip to content

Instantly share code, notes, and snippets.

View vicky7230's full-sized avatar
🎯
Focusing

Vipin Kumar vicky7230

🎯
Focusing
View GitHub Profile
@vicky7230
vicky7230 / Check_if_a_service_is_running_in_an_Activity.java
Created December 17, 2016 05:26
Check if an intent service is running
private boolean isMyServiceRunning(Class<?> serviceClass) {
ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
if (serviceClass.getName().equals(service.service.getClassName())) {
return true;
}
}
return false;
}
Follow this code to sort any ArrayList
Collections.sort(empList, new Comparator<Employee>(){
public int compare(Employee emp1, Employee emp2) {
// ## Ascending order
return emp1.getFirstName().compareToIgnoreCase(emp2.getFirstName()); // To compare string values
// return Integer.valueOf(emp1.getId()).compareTo(emp2.getId()); // To compare integer values
@vicky7230
vicky7230 / MainActivity.java
Last active April 30, 2016 08:34
code to get contact name ,contact number and display them in a listview in android.
package com.cool.vicky.contentprovider;
import android.database.Cursor;
import android.provider.ContactsContract;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.CursorLoader;
import android.support.v4.content.Loader;
import android.support.v4.widget.SimpleCursorAdapter;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
@vicky7230
vicky7230 / android_get_view_size.java
Created November 26, 2015 07:20 — forked from omorandi/android_get_view_size.java
Android: get the actual size of a match_parent/wrap_content view
view.post(new Runnable() {
@Override
public void run() {
int width = view.getWidth();
int height = view.getHeight();
//do something cool with width and height
}
});