Deleted API data not reflecting in android app re-posted

三世轮回 提交于 2020-08-06 07:07:10

问题


I am very experienced developer but very new to mobile app dev. I am using Kotlin, Android Studio & Amplify with a DynamoDB APi. When I add data via the AWS website it shows on the device. When I delete it doesn't reflect unless I uninstall/reinstall. I assume this is some sort of basic cache management/sync issue but like I said I am very new. I have tried removing context.cacheDir but the deleted record persists.

Any help would be appreciated.

Here is some more info. As I say I am predominantly a backend MVC type dev so my approach may be completely wrong but this is just a POC app to learn on. Worth noting is I add a location it appears in the app instantly, just deletes do not reflect.

amplifyConfiguration.json

{
"UserAgent": "aws-amplify-cli/0.1.0",
"Version": "1.0",
"IdentityManager": {
    "Default": {}
},
"AppSync": {
    "Default": {
        "ApiUrl": "https://qhthdepfo5cn5ifjqe4qjihxhy.appsync-api.ap-southeast-2.amazonaws.com/graphql",
        "Region": "ap-southeast-2",
        "AuthMode": "API_KEY",
        "ApiKey": "",
        "ClientDatabasePrefix": "BetsFriends_API_KEY"
    }
},
"api": {
    "plugins": {
        "awsAPIPlugin": {
            "BetsFriends": {
                "endpointType": "GraphQL",
                "endpoint": "https://6w7dl3a42jgkfkpfn3t54crasu.appsync-api.ap-southeast-2.amazonaws.com/graphql",
                "region": "ap-southeast-2",
                "authorizationType": "API_KEY",
                "apiKey": ""
            }
        }
    }
}

}

QuaddieFragment.kt - Fragment load function in KT file to dynamically add buttons

private fun SetLocations(root: View, context: Context?){
    try {
        Amplify.DataStore.query(
            Location::class.java,
            { location ->
                while (location.hasNext()) {
                    i.inc()
                    val loc = location.next()
                    val name = loc.name;
                    val id = loc.id
                    val description: String? = loc.description
                    //create buttons
                    runOnUiThread(Runnable {
                        val linearLayout: LinearLayout =
                            root.findViewById(R.id.quaddie_linear_layout) as LinearLayout
                        val layoutParams = LinearLayout.LayoutParams(
                            LinearLayout.LayoutParams.WRAP_CONTENT,
                            ViewGroup.LayoutParams.WRAP_CONTENT)
                        val buttonDynamic = Button(context)
                        buttonDynamic.layoutParams = layoutParams
                        buttonDynamic.text = name
                        buttonDynamic.id = i
                        if (context != null) {
                            buttonDynamic.background =
                                ContextCompat.getDrawable(context, R.drawable.ic_button_shape)
                        }
                        buttonDynamic.setTextAppearance(context, R.style.ListButtons);
                        linearLayout.addView(buttonDynamic)
                    })

                    Log.i("Location", "Id: $id")
                }
            },
            { failure -> Log.e("Location Query", "Could not query DataStore", failure) }
        )

    } catch (e: Exception){
        Log.e("Location ERROR", e.message)
    }

}

fragment_quaddie.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/quaddie_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.quaddie.QuaddieFragment">

<androidx.constraintlayout.widget.ConstraintLayout
    android:id="@+id/quaddie_constraint_layout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    tools:layout_editor_absoluteX="1dp"
    tools:layout_editor_absoluteY="1dp">

    <LinearLayout
        android:id="@+id/quaddie_linear_layout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:scrollbarAlwaysDrawHorizontalTrack="true"
        android:scrollbarAlwaysDrawVerticalTrack="true"
        tools:layout_editor_absoluteX="1dp"
        tools:layout_editor_absoluteY="1dp"></LinearLayout>
    </androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

来源:https://stackoverflow.com/questions/62987383/deleted-api-data-not-reflecting-in-android-app-re-posted

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!