Sunday, 29 November 2020

When is a fragment not attatched to an activity but only a context?

At the docs for Fragment.getActivity() it says: Return the FragmentActivity this fragment is currently associated with. May return null if the fragment is associated with a Context instead.

But how can a fragment not be associated with an activity? I mean, don't I always need an activity to show anything in Android?



from When is a fragment not attatched to an activity but only a context?

Jetpack Compose model list becomes jumbled when adding new items

I have an issue with Jetpack compose displaying a model containing a ModelList of items. When new items are added, the order of the UI elements becomes incorrect.

Here's a very simple CounterModel containing a ModelList of ItemModels:

@Model
data class CounterModel(
    var counter: Int = 0,
    var name: String = "",
    val items: ModelList<ItemModel> = ModelList()
)

@Model
data class ItemModel(
    var name: String
)

The screen shows two card rows for each ItemModel: RowA and RowB. When I create this screen initialised with the following CounterModel:

val model = CounterModel()
model.name="hi"
model.items.add(ItemModel("Item 1"))
model.items.add(ItemModel("Item 2"))
CounterModelScreen(model)

...it displays as expected like this:

Item 1 Row A

Item 1 Row B

Item 2 Row A

Item 2 Row B

When I click my 'add' button, to insert a new ItemModel, I simply expect to see

Item 3 Row A

Item 3 Row B

At the bottom. But instead, the order is jumbled, and I see two rowAs then two rowBs:

Item 1 Row A

Item 1 Row B

Item 2 Row A

Item 3 Row A

Item 3 Row B

Item 2 Row B

I don't really understand how this is possible. The UI code is extremely simple: loop through the items and emit RowA and RowB for each one:

for (i in counterModel.items.indices) {
    RowA(counterModel, i)
    RowB(counterModel, i)
}

Using Android Studio 4.0C6

Here's the complete code:

@Composable
fun CounterModelScreen(counterModel: CounterModel) {
    Column {
        TopAppBar(title = {
            Text(
                text = "Counter Model"
            )
        })

        CounterHeader(counterModel)
        for (i in counterModel.items.indices) {
            RowA(counterModel, i)
            RowB(counterModel, i)
        }
        Button(
            text = "Add",
            onClick = {
                counterModel.items.add(ItemModel("Item " + (counterModel.items.size + 1)))
            })
    }
}

@Composable
fun CounterHeader(counterModel: CounterModel) {
    Text(text = counterModel.name)
}

@Composable
fun RowA(counterModel: CounterModel, index: Int) {
    Padding(padding = 8.dp) {
        Card(color = Color.White, shape = RoundedCornerShape(4.dp)) {
            Column(crossAxisSize = LayoutSize.Expand) {
                Text(
                    text = counterModel.items[index].name
                )
                Text(text = "Row A")
            }
        }
    }
}

@Composable
fun RowB(counterModel: CounterModel, index: Int) {
    Padding(padding = 8.dp) {
        Card(color = Color.Gray, shape = RoundedCornerShape(4.dp)) {
            Column(crossAxisSize = LayoutSize.Expand) {
                Text(
                    text = counterModel.items[index].name
                )
                Text(text = "Row B")
            }
        }
    }
}


from Jetpack Compose model list becomes jumbled when adding new items

Android app link not working after the application is made live in play store

I have implemented Android app links based on the below links.

https://developer.android.com/studio/write/app-link-indexing.html

https://developer.android.com/training/app-links

I have hosted assetlinks file into our domain https://ourdomain/.well-known/assetlinks.json And also I have verified this using https://developers.google.com/digital-asset-links/tools/generator and from android studio's App Links Assitant also. and got verified status from both the ways.

Now when I generate a signed build and tested it via google drive links. Android app link works as expected(on click of the link the application gets open without opening disambiguation dialog for android version 6.0 and above).

After uploading the same version to play store it's not working.

Below is the code used in the manifest file.

            <intent-filter android:autoVerify="true">
            <action android:name="android.intent.action.VIEW" />

            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />

            <data
                android:scheme="https"
                android:host="<ourdomain>" />
        </intent-filter>

EDIT: Android app link did work as expected for one day after uploading it to the play store. and started opening disambiguation dialog again on the second day. Any idea what could be the issue?

The same version from the play store gave me two different Statuses as Ask and Always on a different day.

enter image description here enter image description here

adb shell dumpsys package domain-preferred-apps

When I run the above command



from Android app link not working after the application is made live in play store