0

Our question is about a listview that uses a recyclerview and is interfaced with a RecyclerAdapter. The ListView will show the data on both the device and emulator. The problem is with the device Samsung SM-T810 with Android 7 APK 24 installed the ListView shows once but if you close the app and restart the ListView no longer show. On the emulator Nexus 5X target & compile SDK 27 min SDK 19 if you close the app and restart the ListView is reloaded and shows data just fine
So the question is this an issue with the code or with the REAL device ? We have checked with DBBrowser and the information is in the listview data is in the appropriate table
We will post the code below

public class TableListView extends AppCompatActivity {

DBHelper dbHelper = new DBHelper(this);

RecyclerView mRecyclerView;
private static RecyclerView.Adapter mAdapter;
private RecyclerView.LayoutManager mLayoutManager;

LinearLayout firstLL;
LinearLayout mainLL;
TextView tvNoData;

static final int READ_BLOCK_SIZE = 100;
static String stringREAD;


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

    setRequestedOrientation( ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

    firstLL = findViewById(R.id.firstLL);
    mainLL = findViewById(R.id.mainLL);
    tvNoData = findViewById(R.id.tvNoData);

    readFROM_TEXT_FILE();

    dbHelper = new DBHelper(this);
    List<TableModel> dbTTList;
    dbTTList = dbHelper.getDataFrom_TABLE_TRACKER();

    int sz = dbTTList.size();

    if(stringREAD.equals("EXTERNAL") || stringREAD.equals("INTERNAL") && sz == 0){
        System.out.println("################ SIZE top "+sz);

        tvNoData.setVisibility(View.VISIBLE);
        tvNoData.setText("No Data Found\n\nClick On Manage Tables");

        mRecyclerView = findViewById(R.id.recycleview);
        mRecyclerView.setHasFixedSize(true);

        mLayoutManager = new LinearLayoutManager(this);
        mRecyclerView.setLayoutManager(mLayoutManager);

        mAdapter = new TableTrackerAdapter(this,dbTTList);
        mRecyclerView.setAdapter(mAdapter);
    }
    if(stringREAD.equals("EXTERNAL") || stringREAD.equals("INTERNAL") && sz > 0){
        System.out.println("################ SIZE bot "+sz);
        mRecyclerView = findViewById(R.id.recycleview);
        mRecyclerView.setHasFixedSize(true);

        mLayoutManager = new LinearLayoutManager(this);
        mRecyclerView.setLayoutManager(mLayoutManager);

        mAdapter = new TableTrackerAdapter(this,dbTTList);
        mRecyclerView.setAdapter(mAdapter);

        tvNoData.setVisibility(View.INVISIBLE);

    }

    setTitle("");// This sets the title of the toolbar
    Toolbar topToolBar = findViewById(R.id.toolbar);
    setSupportActionBar(topToolBar);
    addListenerOnButtonAdd();

    if (Build.VERSION.SDK_INT >= 23) {
        if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {

        } else {
            requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 666);  // Comment 26
        }
    }

}// END onCreate
James_Duh
  • 1,321
  • 11
  • 31
  • what is stringREAD ? all time seem is "" – Cliff May 04 '18 at 23:06
  • @Cliff stringREAD is set in another activity that executes first and is a value EXTERNAL or INTERNAL that is stored in a txt file I tested and the value comes over MY BIG fear now is that my SD CARD might be corrupted and I do not know how to check it – James_Duh May 04 '18 at 23:11

1 Answers1

2

This took some digging into one of your old posts where Comonsware and you were talking about EXTERNAL and INTERNAL storage here is a link here I plugged this code in and made it the launch activity. With a few tweaks we forced this code to re-establish your THE_PATH for some reason this code with out the tweaks was changing the the THE_PATH to INTERNAL storage that was why your data was lost the app was looking for what had been stored EXTERNAL with a INTERNAL path here is the tweaked code from the launcher activity

    public void chkHere(){

    if(stringREAD.equals("EXTERNAL") || stringREAD.equals("INTERNAL")){
        onNEXT(null);
        System.out.println("******************** I WAS FIRED"+THE_PATH);

        Intent intent = new Intent(CheckStorageActivity.this, TableListView.class);
        startActivity(intent);
    }
}

public void onNEXT(View view){

    File fi = new File("storage/");
    File[] lst = fi.listFiles();
    String top = String.valueOf(lst[1]);
    String bot = String.valueOf(lst[0]);
    System.out.println("###################################### top 1 "+top);
    System.out.println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ bot 0 "+bot);

    if(bot.contains("-")){
        STORAGE_LOCATION = 1;
    }
    if(top.contains("storage/enc_emulated")){
        STORAGE_LOCATION = 0;
    }

    if(stringREAD.matches("EMPTY") && STORAGE_LOCATION == 1){
        storageDIALOG();
    }
    if(stringREAD.matches("EMPTY") && STORAGE_LOCATION == 0) {
        internalDIALOG();
    }

    // This Code Below Maintains the variable THE_PATH
    if(stringREAD.matches("EXTERNAL")) {
        STORAGE_LOCATION = 1;
        getThePath();
    }
    if(stringREAD.matches("INTERNAL")){
        STORAGE_LOCATION = 0;
        getThePath();
    }
}
Vector
  • 3,066
  • 5
  • 27
  • 54