Android screen orientation

disable orientation change

<activity android:name=".MainActivity"
    android:screenOrientation="portrait"
    tools:ignore="LockedOrientationActivity">

Handling orientation state
Saving instance state

@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    outState.putInt("ScoreKey", mScore);
    outState.putInt("IndexKey", mIndex);

}

Retrieving instance state

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    if (savedInstanceState != null){
        mScore = savedInstanceState.getInt("ScoreKey");
        mIndex = savedInstanceState.getInt("IndexKey");

    } else {
        mScore = 0;
        mIndex = 0;
    }

Android App Lifecycle

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.d("LifecycleTest", "onCreate");
}
@Override
protected void onStart() {
super.onStart();
Log.d("LifecycleTest", "onStart");
}
@Override
protected void onResume() {
super.onResume();
Log.d("LifecycleTest", "onResume");
}
@Override
protected void onPause() {
super.onPause();
Log.d("LifecycleTest", "onPause");
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
Log.d("LifecycleTest", "onSaveInstanceState");
}
@Override
public void onRestoreInstanceState(Bundle savedInstanceState) {
Log.d("LifecycleTest", "onSaveInstanceState");
}

@Override
protected void onStop() {
super.onStop();
Log.d("LifecycleTest", "onStop");
}
@Override
protected void onDestroy() {
super.onDestroy();
Log.d("LifecycleTest", "onDestroy");
}
}

Android Enable USB-Debugging

  1. goto Settings > General > About phone > Software information and tap “Build number” seven times until it says “You are now a developer”
  2.  Goto Settings > General > Developer options and enable USB Debugging
  3. Drop down the notifications menu and click on “Tap for more USB options”. Most likely, the main title will say “Media Device (MTP)”. Choose the option “Send Images (PTP)”

Internet access in Android

If You want to access some internet resouces from your Android app you add

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

to your AndroidManifest.xml

When You have resources which do not use TLS (https but just http) you have to add

<application
        ...
        android:usesCleartextTraffic="true">
</application>