Skip to content

Instantly share code, notes, and snippets.

String subject = "Subject";
String destinationEmail = "example@example.com";
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("mailto:")); // only email apps should handle this
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
intent.putExtra(Intent.EXTRA_EMAIL, destinationEmail);
Intent mailer = Intent.createChooser(intent, null);
@talosdev
talosdev / SomeActivity.java
Created April 6, 2016 17:28
On logout, when we want to clear the back stack and navigate to a different Activity, the following Intents must be used
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
Intent.FLAG_ACTIVITY_CLEAR_TASK |
Intent.FLAG_ACTIVITY_NEW_TASK);
@talosdev
talosdev / build.gradle
Last active April 22, 2016 12:43
Shared code between test and androidTest
...
android {
...
sourceSets {
String sharedTestDir = 'src/testCommon/java'
androidTest {
java.srcDirs += sharedTestDir
}
@talosdev
talosdev / Mock build flavor
Created May 10, 2016 10:11
Create mockDebug, prodDebug, prodRelease flavors
// If you need to add more flavors, consider using flavor dimensions.
productFlavors {
mock {
applicationIdSuffix = ".mock"
}
prod {
}
}
@talosdev
talosdev / Transitive dependencies (support-annotations)
Last active May 15, 2016 22:40
Solve the issue with transitive dependencies, especially with support-annotations.
/*
Resolves dependency versions across test and production APKs, specifically, transitive
dependencies. This is required since Espresso internally has a dependency on support-annotations.
*/
configurations.all {
resolutionStrategy.force "com.android.support:support-annotations:23.1.1"
}
@talosdev
talosdev / build.gradle
Last active May 23, 2016 13:21
Android Studio memory settings (dex)
dexOptions{
maxProcessCount 2
javaMaxHeapSize "2g"
}
@talosdev
talosdev / [Espresso] test that view is not displayed
Last active May 25, 2016 14:19
check(not(isDisplayed())) will not work, use this instead:
onView(withText(R.string.sort_by_popularity)).check(doesNotExist());
package za.co.riggaroo.retrofittestexample;
import android.content.Context;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
/**
* @author rebeccafranks
package com.listhi.features.discos;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.google.firebase.database.Query;
import java.lang.reflect.Constructor;
@talosdev
talosdev / CustomItemDecoration
Last active October 9, 2016 14:17
RecyclerView dividers with ItemDecoration
final Drawable divider = ContextCompat.getDrawable(context, R.drawable.last_events_divider);
previousEventsRecycler.addItemDecoration(new RecyclerView.ItemDecoration() {
/**
* Draws a divider (1dp-line) inside (over) the child.
* Applies to all elements except the first one.
* @param c
* @param parent
* @param state
*/