CodeHint


Android (26 items)



  API Versions
Name API
Oreo8.0API level 26 e 27
Nougat7.1API level 25
Nougat7.0API level 24
Marshmallow6.0API level 23
Lollipop5.1API level 22
Lollipop5.0API level 21
KitKat4.4API level 19
Jelly Bean4.3.xAPI level 18
Jelly Bean4.2.xAPI level 17
Jelly Bean4.1.xAPI level 16
I C Sandwich4.0.3 - 4.0.4API level 15
I C Sandwich4.0.1 - 4.0.2API level 14
Honeycomb3.2.xAPI level 13
Honeycomb3.1API level 12
Honeycomb3.0API level 11
Gingerbread2.3.3 - 2.3.7API level 10
Gingerbread2.3 - 2.3.2API level 9
Froyo2.2.xAPI level 8
  Edit
  Fullscreen example
protected void onCreate(Bundle b)
{
   super.onCreate(b);
   requestWindowFeature(Window.FEATURE_NO_TITLE);
   getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
   setContentView(R.layout.main);
}
  Edit
  Main folder : app/src/main

Thats it

  Edit
  Decode stream to Bitmap
InputStream is = getResources().openRawResource(R.drawable.icon);
Bitmap bmp = BitmapFactory.decodeStream(is);
  Edit
    android:configChanges="orientation|screenSize|keyboardHidden"

Set inside activity on manifest to prevent activity reset on orientation changing

  Edit
    public boolean onCreateOptionsMenu(Menu menu)
    public boolean onOptionsItemSelected(MenuItem item)
    android:style="@android:style/Theme.Dialog"

Set style inside activity

  Edit
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

Set new wake lock instead of that one from PowerManager

  Edit
  ViewFlipper Example

viewFlipper example

  Edit
    getSharedPreferences(name, mode)
Returns SharedPreferences. Modes ?
Context.MODE_PRIVATE
Context.MODE_WORLD_READABLE
Context.MODE_WORLD_WRITABLE
Context.MODE_MULTI_PROCESS
  Edit
    Environment.getExternalStorageState()
Returns storage state:
Environment.MEDIA_MOUNTED
Environment.MEDIA_CHECKING
Environment.MEDIA_REMOVED
Environment.MEDIA_MOUNTED_READ_ONLY
  Edit
  AsyncTask Example
  HttpURLConnection Example
try{
   String result = "";
   URL url = new URL(site);
   HttpURLConnection = (HttpURLConnection) url.openConnection();
   conn.setDoInput(true);
   conn.setConnectTimeout(10000);
   int responseCode = conn.getResponseCode();
  
   if(responseCode == HttpURLConnection.HTTP_OK) {
      InputStream is = new BufferedInputStream(conn.getInputStream);
      BufferedReader br = new BufferedReader(new InputStreamReader(is));
      StringBuilder sb = new StringBuilder();
      String line;
      while((line=br.readLine()) != null) {
         sb.append(line);
      }
      result = sb.toString();
   }
   conn.disconnect();
}catch(Exception e){
   e.printStackTrace();
}
  Edit
  System.exit(0) VS finish()
System.exit(0) - The VM stops further execution and program will exit.
finish() - Call this when your activity is done and should be closed. The ActivityResult is propagated back to whoever launched you via onActivityResult().
  Edit
  Log API Levels
VERBOSE Log.v (String tag, String msg)
DEBUG Log.d (String tag, String msg)
INFO Log.i (String tag, String msg)
WARNING Log.w (String tag, String msg)
ERROR Log.e (String tag, String msg)
  Edit
    String greetings = getResources().getString(R.string.greetings);

Get string resource programatically

  Edit
  Icon Sizes
Resolution  DPI  Size
MDPI16048x48
HDPI24072x72
XHDPI32096x96
XXHDPI480144x144
XXXHDPI640192x192
  Edit
  Animation Example
Animation anim = AnimationUtils.loadAnimation(this, R.anim.example);
imageView.startAnimation(anim);
  Edit
    <include layout="@layout/greenlayout" />

Include layout inside another layout

  Edit
    android:singleLine="true"

Single line on EditText

  Edit
  ViewTreeObserver 3 Events (entire screen)
* addOnPreDrawListener()
* addOnGlobalLayoutLIstener()
* addOnFocusChangeListener()
  Edit
  XML Style example
<?xml version="1.0" encoding="utf-8"?>
<resources>
   <style name="padded_small" parent="paDAD_red">
      <item name="android:padding">12dp</item>
      <item name="android:textSize">12sp</item>
   </style>
   <style name="padded_large">
      <item name="android:padding">24dp</item>
      <item name="android:textSize">24sp</item>
   </style>
</resources>
  Edit
    intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES)

Just remember that when you make your sendBroadcast(intent)

  Edit
  Force hide keyboard
this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN)
  Edit
keytool -exportcert -keystore keystore -list -v

Verify keystore contents

  Edit