1

I have a probleme when I lock my phone and unlock in one Activity always call onCreate . Maybe someone can help me ? This is my onCreate , maybe I do something wrong , which call a onCreate. On create is call in my app when be first time in app and when I unlock a phone , but when I mminimalize my app and open a app my app call onResume

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

        MainActivity.logOut = true;
//        i = new Intent(getApplicationContext(), Sync.class);
//        startService(i);
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
        columns.add("nazwa");
        columns.add("start");
        sp = getSharedPreferences("pfref", Activity.MODE_PRIVATE);
        editor = sp.edit();

        placeholder = (TextView) findViewById(R.id.list_placeholder);
        buttonsHolder = new ArrayList<>();
        resultReceiver = new MyResultReceiver(new Handler());
        initializeView();
        swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_refresh_layout);
        managerDB = ManagerDB.getInstance(getApplicationContext(), "name");
        progressBar = (ProgressBar) findViewById(R.id.pbWheel);
        tasks = new ArrayList<>();
        tasks.clear();
        btShowAll.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                routeDetailsShow();
            }
        });
        btNotDone = (Button) findViewById(R.id.all_items_not_done);
        btPhotoToSend = (Button) findViewById(R.id.bt_photo_to_send);
        btShowAllNotes = (Button) findViewById(R.id.bt_show_all_note);
        imgIsSend = (ImageView) findViewById(R.id.send);
        imgIsNet = (ImageView) findViewById(R.id.net);
        if (!MainActivity.xmlList.isEmpty()) {
            imgIsSend.setImageResource(R.drawable.red_arrow);
        } else {
            imgIsSend.setImageResource(R.drawable.green_arrow);
        }
        if (sp.getBoolean("serverOff", false) || sp.getBoolean("workOffLine", false)) {
            imgIsNet.setVisibility(View.VISIBLE);
        } else {
            imgIsNet.setVisibility(View.GONE);
        }
        btSort = (Button) this.findViewById(R.id.static_filter);
        btSort.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (!isSort)
                    showChangeLangDialog();
                else {
                    tasks.clear();
                    if (!isFiltr) {
                        getAllTasks();
                    } else {
                        getAllTasks2(column[0], sort[0], filtrText);
                    }
                    Page page = config.getItems().get(0).getPages().get(0);
                    myAdapter = new NewDataAdapter(MainActivity.this, parseWyborTrasyToDataRow(tasks), page);
                    lista.setAdapter(myAdapter);
                    isSort = false;
                    btSort.setTextColor(Color.BLACK);
                    btSort.setText("Sortowanie");
                }
            }
        });


        btFiltr = (Button) findViewById(R.id.static_filter2);
        btFiltr.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (!isFiltr) {
                    showChangeLangDialog2();
                } else {
                    tasks.clear();
                    if (!isSort) {
                        getAllTasks();
                    } else {
                        getAllTasks1(sortColumn[0], sort[0]);
                    }
                    Page page = config.getItems().get(0).getPages().get(0);
                    myAdapter = new NewDataAdapter(MainActivity.this, parseWyborTrasyToDataRow(tasks), page);
                    lista.setAdapter(myAdapter);
                    isFiltr = false;
                    btFiltr.setTextColor(Color.BLACK);
                    btFiltr.setText("Filtrowanie");

                }
            }
        });

        btShowAllNotes.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                showAllNotes();
            }
        });

        btShowAll.setEnabled(false);
        btNotDone.setEnabled(false);

        Gson gson = new Gson();
        List<File> productFromShared = new ArrayList<>();
        SharedPreferences sharedPref = getApplicationContext().getSharedPreferences("TAG", Context.MODE_PRIVATE);
        String jsonPreferences = sharedPref.getString("TAG", "");

        Type type = new TypeToken<List<File>>() {
        }.getType();
        productFromShared = gson.fromJson(jsonPreferences, type);
        photoListSend = null;
        photoListSend = new ArrayList<>();
        if (productFromShared != null)
            photoListSend.addAll(productFromShared);

        List<String> productFromShared1 = new ArrayList<>();
        String jsonPreferences1 = sharedPref.getString("TAG1", "");

        Type type1 = new TypeToken<List<String>>() {
        }.getType();
        productFromShared1 = gson.fromJson(jsonPreferences1, type1);
        MainActivity.xmlList = null;
        MainActivity.xmlList = new ArrayList<>();
        if (productFromShared1 != null)
            xmlList.addAll(productFromShared1);


        btPhotoToSend.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!isSend) {
                    photoList();
                } else {
                    Toast.makeText(MainActivity.this, "Trwa wysyłanie zdjęć ", Toast.LENGTH_LONG).show();
                }
            }
        });

        btNotDone.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                notDone();
            }
        });
        lista.setOnScrollListener(new AbsListView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(AbsListView view, int scrollState) {
            }

            @Override
            public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
                boolean enable = false;
                if (lista != null && lista.getChildCount() > 0) {
                    boolean firstItemVisible = lista.getFirstVisiblePosition() == 0;
                    boolean topOfFirstItemVisible = lista.getChildAt(0).getTop() == 0;
                    enable = firstItemVisible && topOfFirstItemVisible;
                }
                swipeRefreshLayout.setEnabled(enable);
            }
        });

        observer = new ContentObserver(new Handler(Looper.myLooper())) {
            public void onChange(boolean selfChange) {
                swipeRefreshLayout.setRefreshing(false);
                CheckerThread1 thread = new CheckerThread1(getApplicationContext());
                thread.execute();
                GPSTracker.getInstance(getApplicationContext());
            }
        };
        failureObserver = new ContentObserver(new Handler(Looper.myLooper())) {
            @Override
            public void onChange(boolean selfChange) {
                swipeRefreshLayout.setRefreshing(false);
            }
        };

        placeholder.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent event) {
                if (NetworkUtils.isNetworkAvailable(getApplicationContext())) {
                    if (event.getAction() == MotionEvent.ACTION_DOWN) {
                        CheckerThread1 thread = new CheckerThread1(getApplicationContext());
                        thread.execute();
                        GPSTracker.getInstance(getApplicationContext());
                        isRefresh = true;
                        swipeRefreshLayout.setRefreshing(true);
                        showPlaceholder(myAdapter);
                    }
                } else {
                    swipeRefreshLayout.setRefreshing(false);
                    Toast.makeText(getApplicationContext(), "Nie ma dostępu do internetu", Toast.LENGTH_LONG).show();
                }
                return false;
            }
        });

//        placeholder.setOnTouchListener((v, event) -> {
//            if (NetworkUtils.isNetworkAvailable(getApplicationContext())) {
//                if (event.getAction() == MotionEvent.ACTION_DOWN) {
//                    CheckerThread1 thread = new CheckerThread1(getApplicationContext());
//                    thread.execute();
//                    GPSTracker.getInstance(getApplicationContext());
//                    isRefresh = true;
//                    swipeRefreshLayout.setRefreshing(true);
//                }
//            } else {
//                swipeRefreshLayout.setRefreshing(false);
//                Toast.makeText(getApplicationContext(), "Nie ma dostępu do internetu", Toast.LENGTH_LONG).show();
//            }
//            return false;
//        });

        swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                isSwipe = true;
                if (NetworkUtils.isNetworkAvailable(getApplicationContext())) {
                    CheckerThread thread = new CheckerThread(getApplicationContext());
                    thread.execute();
                    GPSTracker.getInstance(getApplicationContext());
                    isRefresh = true;
                    swipeRefreshLayout.setRefreshing(true);
                } else {
                    isRefresh = false;
                    swipeRefreshLayout.setRefreshing(false);
                    Toast.makeText(getApplicationContext(), "Nie ma dostępu do internetu", Toast.LENGTH_LONG).show();
                }
            }
        });
        View view = this.getCurrentFocus();
        if (view != null) {
            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
        }
        if (LoginActivity.showProgresBar) {
//            LoginActivity.showProgresBar = true;
            CheckerThread thread = new CheckerThread(this);
            thread.execute();
            showProgresBar = false;
            GPSTracker.getInstance(this);
        } else {
            if (config != null) {
                gpsSwitchOnly = true;
                setCaption();
                refreshTables();
                if (!SyncConnection.running) {
                    fireUpSync(config.getSync());
                }
            }
        }
    }

Manifest :

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.eltegps022.smokkomunal">

    <uses-feature android:name="android.hardware.camera" />
    <uses-feature android:name="android.hardware.camera.autofocus" />

    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".Activity.LoginActivity"
            android:windowSoftInputMode="stateVisible|adjustResize">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".Activity.AdminPanelActivity"
            android:windowSoftInputMode="stateVisible|adjustResize" />
        <activity
            android:name=".Activity.MainActivity"
            android:screenOrientation="landscape"
            android:windowSoftInputMode="stateHidden|adjustResize" />

        <service
            android:name=".sync.SyncOnceConnection"
            android:singleUser="true" />
        <service
            android:name=".sync.SyncOnceConnection"
            android:singleUser="true" />
        <service android:name=".photos.PhotoSender" />

        <activity
            android:name=".Activity.RouteDetailsActivity"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:screenOrientation="landscape" />
        <activity
            android:name=".Activity.NotePGOActivity"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:screenOrientation="landscape" />
        <activity
            android:name=".Activity.SignatureActivity"
            android:screenOrientation="landscape" />
        <activity
            android:name=".Activity.PhotoListActivity"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:screenOrientation="landscape" />
        <activity
            android:name=".Activity.ConfirmPGOActivity"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:screenOrientation="landscape" />
        <activity
            android:name=".Activity.DetailsPGOActivity"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:screenOrientation="landscape" />
        <activity
            android:name=".Activity.ConfirmDetailsPGOActivity"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:screenOrientation="landscape" />
        <activity
            android:name=".Activity.ExtraCargoActivity"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:screenOrientation="landscape" />
        <activity
            android:name=".Activity.NoteToCargoActivity"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:screenOrientation="landscape" />

        <service android:name=".Service.Sendrer" />
        <service android:name=".Service.SenderXML" />
        <service android:name=".Service.Sync" />


        <activity
            android:name=".Activity.RouteDetailsNotDoneActivity"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:screenOrientation="landscape" />
        <activity
            android:name=".Activity.PhotoListToSendActivity"
            android:screenOrientation="landscape" />
        <activity
            android:name=".Activity.ShowAllNoteActivity"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:screenOrientation="landscape" />
        <activity
            android:name=".Activity.ShowAllNotesActivity"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:screenOrientation="landscape" />
        <provider
            android:name="android.support.v4.content.FileProvider"
            android:authorities="${applicationId}.provider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/provider_paths"/>
        </provider>
    </application>

</manifest>
Krzysztof Pokrywka
  • 1,356
  • 4
  • 27
  • 50

1 Answers1

0

I change a my manifest : I add this : android:configChanges="orientation|keyboardHidden|screenSize" because :

To declare that your activity handles a configuration change, edit the appropriate element in your manifest file to include the android:configChanges attribute with a value that represents the configuration you want to handle. Possible values are listed in the documentation for the android:configChanges attribute (the most commonly used values are "orientation" to prevent restarts when the screen orientation changes and "keyboardHidden" to prevent restarts when the keyboard availability changes). You can declare multiple configuration values in the attribute by separating them with a pipe | character.

Krzysztof Pokrywka
  • 1,356
  • 4
  • 27
  • 50