Skip to content

Instantly share code, notes, and snippets.

@mstoic
mstoic / clear_top_stack.java
Last active September 10, 2018 07:28
A flag to close all previous activities of your app
// Close all previous activities
// https://stackoverflow.com/questions/6330260/finish-all-previous-activities
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
// 10-09-18 - Not working in App Lock.
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
@mstoic
mstoic / disable_animation_activity.java
Created September 10, 2018 08:18
Completely disable all opening application for an activity.
// Source: https://stackoverflow.com/a/11079475
// Add below code to styles.xml
<style name="noAnimTheme" parent="AppTheme.NoActionBar">
<item name="android:windowAnimationStyle">@null</item>
</style>
// Set below theme for Activity in Manifest
// Add Below Code oncreate
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
// Add below code in activity
@Override
public boolean onSupportNavigateUp(){
finish();
return true;
}
// See all the settings pages
// https://developer.android.com/reference/android/provider/Settings
try {
context.startActivity(new Intent(Settings.ACTION_FINGERPRINT_ENROLL));
} catch (Exception e) {
e.printStackTrace();
}
app:backgroundTint="@color/colorMuted"
android:tint="@color/colorBlack"
KeyguardManager myKM = (KeyguardManager) getApplicationContext().getSystemService(Context.KEYGUARD_SERVICE);
if( myKM.inKeyguardRestrictedInputMode()) {
// Phone is locked
return;
}
@mstoic
mstoic / get_foreground_app
Last active September 27, 2018 11:11
Crashes on devices before Lolipop
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public String getForegroundApp(Context context) {
String currentApp = "NULL";
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
try {
Class.forName( "android.app.usage.UsageStatsManager" );
UsageStatsManager usm = (UsageStatsManager) context.getSystemService(Context.USAGE_STATS_SERVICE);
long time = System.currentTimeMillis();
List<UsageStats> appList = usm.queryUsageStats(UsageStatsManager.INTERVAL_DAILY, time - 1000 * 1000, time);
if (appList != null && appList.size() > 0) {
android:fillViewport="true"
$('.xenForm').find('fieldset').each(function() {
$(this).find('input[value="delete"]').prop("checked", true);
});
@mstoic
mstoic / reverse_a_string_using_string_class
Last active September 1, 2020 19:43
Reverse a String
String originalString = "This is Mstoic Blog";
String reversedString = "";
for (int i = 1; i <= originalString.length(); i++) {
reversedString += (originalString.charAt(originalString.length()-i));
}
System.out.println("Reversed: " + reversedString);