<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by YADNYESH RANA on Medium]]></title>
        <description><![CDATA[Stories by YADNYESH RANA on Medium]]></description>
        <link>https://medium.com/@yadnyesh_rana?source=rss-371517939594------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*14o07_lfTHUVh_vd1K0KUA.jpeg</url>
            <title>Stories by YADNYESH RANA on Medium</title>
            <link>https://medium.com/@yadnyesh_rana?source=rss-371517939594------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 17:35:13 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@yadnyesh_rana/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[MemoryLimiter:AnonSwap Is Why Your App Is Killed on Android 17]]></title>
            <link>https://medium.com/@yadnyesh_rana/memorylimiter-anonswap-is-why-your-app-is-killed-on-android-17-2baf18970f04?source=rss-371517939594------2</link>
            <guid isPermaLink="false">https://medium.com/p/2baf18970f04</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[mobile]]></category>
            <dc:creator><![CDATA[YADNYESH RANA]]></dc:creator>
            <pubDate>Sat, 07 Nov 2026 06:24:08 GMT</pubDate>
            <atom:updated>2026-11-07T06:24:08.533Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wGTTtGhUt2mH_bO5USrqPw.png" /></figure><p>Android 17 puts a ceiling on how much memory your app may hold, sized from the device’s total RAM. Cross it and the process is killed. There is no exception, so there is no stack trace, no Crashlytics event and no entry in the Play Console’s crash list. The user tells you the app closed itself and every dashboard you own agrees that nothing happened.</p><p>This one is not gated on targetSdkVersion. There is no manifest flag to set and no recompile that avoids it — the behaviour arrives with the operating system, for every app already installed.</p><p>The record does exist. It is written once, into an API most codebases never call: ApplicationExitInfo, with getReason() returning REASON_OTHER and a description containing the string MemoryLimiter:AnonSwap.</p><p>That string is the whole diagnosis, and you can only read it on the <em>next</em> launch.</p><h3>What the limiter is for</h3><p>Google’s stated target is leaks and outliers rather than ordinary sessions: a process that holds memory it will never use again degrades the whole device, and the system would previously let it do that until something else died. The ceiling is derived from total RAM, so a 4GB phone enforces a lower one than a 12GB flagship, and the same build can be killed on one and fine on the other.</p><p>If your app’s memory profile is flat and modest, you will likely never meet it. If you have a leak you have been carrying for two years because it never caused a visible crash, Android 17 is the release where it starts costing you sessions.</p><h3>Why your crash reporter is empty</h3><p>A kill is not a crash. The process receives no signal it can report on, nothing unwinds, and your reporting SDK never runs. From inside the app, the last thing that happens is nothing at all.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dBgkw3CF-lWtpONaGZllnw.png" /></figure><p>This is why the bug arrives as a support ticket rather than an alert, and why it survives weeks of triage: the only team member who can see it is the user, and all they can tell you is that it vanished.</p><h3>Reading the exit record</h3><p>ActivityManager.getHistoricalProcessExitReasons has been available since API 30 and returns the system&#39;s record of how your recent processes ended. The check for a limiter kill is a reason and a substring:</p><pre>@RequiresApi(Build.VERSION_CODES.R)<br>fun ApplicationExitInfo.isMemoryLimiterKill(): Boolean =<br>    reason == ApplicationExitInfo.REASON_OTHER &amp;&amp;<br>        description?.contains(&quot;MemoryLimiter:AnonSwap&quot;) == true</pre><p>Read it once per launch, as early as you have a Context:</p><pre>class ExitReasonReporter(private val context: Context) {<br><br>fun report(onLimiterKill: (ApplicationExitInfo) -&gt; Unit) {<br>        if (Build.VERSION.SDK_INT &lt; Build.VERSION_CODES.R) return<br>        val activityManager = context.getSystemService(ActivityManager::class.java) ?: return<br>        val records = activityManager.getHistoricalProcessExitReasons(<br>            context.packageName,<br>            0,   // all pids<br>            10,  // most recent 10 exits<br>        )<br>        records.filter { it.isMemoryLimiterKill() }.forEach(onLimiterKill)<br>    }<br>}</pre><p><em>Look at the two numbers.</em> Passing 0 for the pid asks for every process, not just the last one, which matters because the kill you care about may be two launches back by the time anyone reports it. Ten records is enough history to survive a weekend without being so many that parsing them delays startup.</p><p>Wire it into Application.onCreate so it runs exactly once:</p><pre>class App : Application() {<br><br>override fun onCreate() {<br>        super.onCreate()<br>        ExitReasonReporter(this).report { exit -&gt;<br>            analytics.log(<br>                event = &quot;memory_limiter_kill&quot;,<br>                params = mapOf(<br>                    &quot;pss_kb&quot; to exit.pss,<br>                    &quot;rss_kb&quot; to exit.rss,<br>                    &quot;at&quot; to exit.timestamp,<br>                    &quot;importance&quot; to exit.importance,<br>                ),<br>            )<br>        }<br>    }<br>}</pre><p>getPss() and getRss() are the sizes recorded at death, in kilobytes. Log them. &quot;The app was killed for memory&quot; is a shrug; &quot;the app was killed holding 512MB of RSS on a 4GB device, on the photo editor screen&quot; is a bug you can assign to someone.</p><p>importance is worth capturing too: a kill while the app was in the foreground is a different problem from one that happened after the user left.</p><h3>Reproducing it on purpose</h3><p>A report you cannot reproduce gets closed. The platform ships three adb subcommands that make this one reproducible on demand:</p><pre>adb shell am memory-limiter status<br>adb shell am memory-limiter manual &lt;pid&gt; 200<br>adb shell am memory-limiter ignore &lt;uid&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MrHar1OHSJKT3R2Wi9ETEA.png" /></figure><p>status reports the limits currently imposed on visible and non-visible processes, and it is the first thing to run: these commands do nothing at all on a device that imposes no limits, and you want to know that before you spend an hour concluding your app is innocent.</p><p>manual forces a ceiling on one process, in megabytes. Set it low, open the screen you suspect, and the kill arrives on your desk instead of a stranger&#39;s. Pass max to lift it again, or none to return the process to the system default.</p><p>ignore takes a UID out of enforcement entirely, which is the cleanest way to answer the only question that matters during triage: <em>is the limiter doing this, or is it something else?</em> Exempt the app, repeat the steps, and see whether the death goes away.</p><p>One caution on ignore all: it is useful for a few minutes of bisecting and useless as a test configuration. A QA device that permanently ignores the limiter is a device that can no longer reproduce the bug your users are hitting, which is the state most teams end up in by accident.</p><h3>What to do once you can see it</h3><p>Everything above only tells you the limiter fired. The fix is ordinary memory work: find what the process is holding and stop holding it. Record a baseline first, because without one you cannot tell whether a change helped or whether the device simply had a quieter day.</p><p>For the moment of the kill itself, trigger-based profiling with TRIGGER_TYPE_ANOMALY captures a heap dump when the limit is hit, which is considerably more useful than a dump taken whenever a developer happened to be watching.</p><h3>Before you ship</h3><ul><li>getHistoricalProcessExitReasons is read once per launch and the result reaches your telemetry</li><li>Limiter kills are separated from ordinary low-memory kills in your dashboards — they are a different failure with a different fix</li><li>pss, rss, timestamp and importance are logged with every one, not just a count</li><li>Tested on at least one low-RAM device, not only the 12GB phone on your desk</li><li>The suspect screens were run under am memory-limiter manual with a deliberately low ceiling</li><li>No QA device is left in am memory-limiter ignore</li><li>A memory baseline exists for the screens most likely to be holding something</li></ul><p>The detection code is nine lines and the rest is the work you were already avoiding. What changes in Android 17 is only that the bill now arrives as vanished sessions instead of a slow device, and that the receipt is written somewhere you have to go and look.</p><h3>Continue reading</h3><p><a href="https://medium.com/stackademic/screenorientation-is-ignored-when-you-target-android-16-2e1b5b1e78fd"><strong>[screenOrientation Is Ignored When You Target Android 16]</strong> — the other platform change that breaks quietly, and the one that only appears on tablets and unfolded foldables</a>.</p><p><a href="https://medium.com/stackademic/onbackpressed-stops-being-called-when-you-target-android-16-0d091980c3d1"><strong>[onBackPressed() Stops Being Called When You Target Android 16]</strong> — back handling stops running at targetSdk 36, with no crash and no warning either.</a></p><p><em>Follow if you are working through platform behaviour changes. The next one is whatever breaks without an error message.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2baf18970f04" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Your Edge-to-Edge Opt-Out Stops Working When You Target Android 16]]></title>
            <link>https://blog.stackademic.com/your-edge-to-edge-opt-out-stops-working-when-you-target-android-16-9235325914d3?source=rss-371517939594------2</link>
            <guid isPermaLink="false">https://medium.com/p/9235325914d3</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[jetpack-compose]]></category>
            <dc:creator><![CDATA[YADNYESH RANA]]></dc:creator>
            <pubDate>Thu, 08 Oct 2026 20:01:09 GMT</pubDate>
            <atom:updated>2026-10-08T20:01:09.393Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m1hem4HjR88aYQbCrIOSEw.png" /></figure><p>If your theme still carries windowOptOutEdgeToEdgeEnforcement, it stopped doing anything the day you set targetSdk to 36. The attribute is deprecated and disabled for apps targeting API 36, so your content now draws behind the status and navigation bars whether you were ready or not.</p><p>It is gated on two things at once, which makes it confusing to reproduce: the app must target 36 <strong>and</strong> the device must run Android 16. Target 36 and install on an Android 15 handset and the opt-out still works, which is how a team convinces itself the migration is done.</p><p>The other two breaking changes in this release still have escape hatches. Predictive back has enableOnBackInvokedCallback=&quot;false&quot;. The large-screen orientation override has a property that lasts until API 37. This one has nothing. The inset work is now mandatory.</p><p>Most of that work is one padding call. What costs an afternoon is the second bug: the first fix often leaves a gap exactly twice the height of the status bar, and the reason is not in the code you just wrote.</p><h3>Insets are a tree, and padding consumes</h3><p>A window hands its insets to the top of your view tree: status bar 48dp at the top, navigation bar 24dp at the bottom, give or take the device. Every layer that pads for part of that inset <strong>consumes</strong> it, so the layers below see only what is left.</p><p>That is the whole model, and it is what makes composition work. Scaffold pads its content for the system bars and consumes them, so a child that also asks for safeDrawing gets zero and adds nothing.</p><p>The trap is a function that does not participate in consumption: WindowInsets.safeDrawing.asPaddingValues() reads the raw window insets. It does not know what a parent already consumed. Pass that into a list&#39;s contentPadding underneath a Scaffold and the 48dp lands a second time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z_8obQnM9S6c-hVAxA8wOw.png" /></figure><h3>The Compose fix, and the gap that doubles</h3><p>Scaffold already does the right thing if you let it:</p><pre>@Composable<br>fun OrdersScreen(orders: List&lt;Order&gt;) {<br>    Scaffold(<br>        topBar = { TopAppBar(title = { Text(&quot;Orders&quot;) }) },<br>    ) { innerPadding -&gt;<br>        LazyColumn(<br>            contentPadding = innerPadding,<br>            modifier = Modifier.fillMaxSize(),<br>        ) {<br>            items(orders, key = { it.id }) { order -&gt;<br>                OrderRow(order)<br>            }<br>        }<br>    }<br>}</pre><p>innerPadding is what the Scaffold has already worked out and not consumed on your behalf — the bar heights plus whatever system insets remain. Handing it to contentPadding keeps the first and last rows clear of the bars while the list still scrolls underneath them, which is the look the enforcement is asking for.</p><p>The version that produces the double gap looks just as reasonable:</p><pre>// Wrong: asPaddingValues() ignores what the Scaffold already consumed.<br>LazyColumn(<br>    contentPadding = WindowInsets.safeDrawing.asPaddingValues(),<br>    modifier = Modifier.fillMaxSize(),<br>)</pre><p>If you need a container to stop pretending the insets are still there — a custom layout between the Scaffold and a child that pads for itself — consume them explicitly:</p><pre>Box(<br>    modifier = Modifier<br>        .fillMaxSize()<br>        .consumeWindowInsets(innerPadding),<br>) {<br>    SettingsPanel()<br>}</pre><p>Now SettingsPanel can call Modifier.safeDrawingPadding() without double-counting, because there is nothing left to count.</p><h3>Which inset do you actually want</h3><p>safeDrawing is the default answer and covers anything that must not be drawn over: system bars, display cutout, and the IME when it is up.</p><p>The others matter in specific cases. systemBars alone ignores the notch, which is fine for a bottom bar and wrong for a top one on a cutout device. safeGestures covers the areas where the system takes the gesture first, which is what a bottom sheet or a horizontal carousel needs so your drag does not become a back swipe. safeContent is both.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KGRj7k8XRJBrJ30D3tDbwQ.png" /></figure><p>Two rules survive every project. Pad tappable things with safeDrawing or they end up under the navigation bar. Do not pad scrolling content — give it contentPadding instead, so the content passes under the bars and stops in the right place.</p><h3>The Views fix</h3><p>Edge-to-edge in Views is one call plus one listener:</p><pre>class OrdersActivity : AppCompatActivity() {<br><br>private lateinit var binding: ActivityOrdersBinding<br><br>override fun onCreate(savedInstanceState: Bundle?) {<br>        enableEdgeToEdge()<br>        super.onCreate(savedInstanceState)<br>        binding = ActivityOrdersBinding.inflate(layoutInflater)<br>        setContentView(binding.root)<br>        ViewCompat.setOnApplyWindowInsetsListener(binding.toolbar) { view, windowInsets -&gt;<br>            val bars = windowInsets.getInsets(<br>                WindowInsetsCompat.Type.systemBars() or WindowInsetsCompat.Type.displayCutout()<br>            )<br>            view.updatePadding(top = bars.top, left = bars.left, right = bars.right)<br>            WindowInsetsCompat.CONSUMED<br>        }<br>        ViewCompat.setOnApplyWindowInsetsListener(binding.recyclerView) { view, windowInsets -&gt;<br>            val bars = windowInsets.getInsets(<br>                WindowInsetsCompat.Type.systemBars() or WindowInsetsCompat.Type.displayCutout()<br>            )<br>            view.updatePadding(bottom = bars.bottom, left = bars.left, right = bars.right)<br>            WindowInsetsCompat.CONSUMED<br>        }<br>    }<br>}</pre><p>enableEdgeToEdge() goes <strong>before</strong> super.onCreate. Returning WindowInsetsCompat.CONSUMED is the Views equivalent of consumption: it stops the insets travelling further down, which is exactly what you want once you have padded for them, and exactly what you do not want if a sibling still needs them. Return windowInsets unchanged instead when something below still has to see them.</p><p>One attribute in the layout does the rest:</p><pre>&lt;androidx.recyclerview.widget.RecyclerView<br>    android:id=&quot;@+id/recyclerView&quot;<br>    android:layout_width=&quot;match_parent&quot;<br>    android:layout_height=&quot;match_parent&quot;<br>    android:clipToPadding=&quot;false&quot; /&gt;</pre><p>Without clipToPadding=&quot;false&quot;, the padding you just added becomes a dead strip the list refuses to scroll into, and the effect is a list that stops short of the navigation bar instead of flowing under it.</p><h3>The keyboard</h3><p>ime is not part of safeDrawing in the way people assume: it is included, but only while the keyboard is actually showing, and it animates. For a screen with a text field at the bottom, let Compose follow it:</p><pre>Column(<br>    modifier = Modifier<br>        .fillMaxSize()<br>        .imePadding(),<br>) {<br>    MessageList(modifier = Modifier.weight(1f))<br>    MessageInput()<br>}</pre><p>imePadding() tracks the keyboard animation frame by frame, so the input rides up with it instead of jumping when the animation ends.</p><h3>Before you ship</h3><ul><li>Tested on an Android 16 device or emulator — an Android 15 one still honours the dead opt-out</li><li>Checked with gesture navigation <strong>and</strong> three-button navigation; the bottom inset differs</li><li>Checked on a device with a display cutout, in both portrait and landscape</li><li>Every tappable control sits above the navigation bar</li><li>Lists scroll under the bars rather than stopping at them (clipToPadding=&quot;false&quot;, or contentPadding in Compose)</li><li>No screen pads the same inset twice — if a gap looks like two status bars, it is</li><li>The keyboard pushes the input field rather than covering it</li><li>windowOptOutEdgeToEdgeEnforcement is deleted from the theme, not left to rot</li></ul><p>That last one is bookkeeping, but it is the honest kind. The attribute does nothing at API 36 and will mislead whoever opens the theme next, exactly the way it misled the team that thought it still had an opt-out.</p><h3>Continue reading</h3><p><a href="https://medium.com/stackademic/onbackpressed-stops-being-called-when-you-target-android-16-0d091980c3d1"><strong>[onBackPressed() Stops Being Called When You Target Android 16]</strong> </a>— the cluster’s other silent break. If you are doing inset work today, back handling is the one you have not checked yet.</p><p><a href="https://medium.com/stackademic/screenorientation-is-ignored-when-you-target-android-16-2e1b5b1e78fd"><strong>[screenOrientation Is Ignored When You Target Android 16]</strong></a> — the layout half of the same migration, and it only shows up on tablets and unfolded foldables.</p><p><em>That is the last of the three targetSdk 36 changes that break without an error. Follow if you are working through the same migration.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9235325914d3" width="1" height="1" alt=""><hr><p><a href="https://blog.stackademic.com/your-edge-to-edge-opt-out-stops-working-when-you-target-android-16-9235325914d3">Your Edge-to-Edge Opt-Out Stops Working When You Target Android 16</a> was originally published in <a href="https://blog.stackademic.com/">Stackademic</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[screenOrientation Is Ignored When You Target Android 16]]></title>
            <link>https://blog.stackademic.com/screenorientation-is-ignored-when-you-target-android-16-2e1b5b1e78fd?source=rss-371517939594------2</link>
            <guid isPermaLink="false">https://medium.com/p/2e1b5b1e78fd</guid>
            <category><![CDATA[jetpack-compose]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[YADNYESH RANA]]></dc:creator>
            <pubDate>Thu, 01 Oct 2026 18:42:57 GMT</pubDate>
            <atom:updated>2026-10-01T18:42:57.085Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9zU_v7rvKkrqc6O0ujYbiQ.png" /></figure><p>Set targetSdk to 36 and your portrait lock stops working on any display whose smallest width is 600dp or more. android:screenOrientation=&quot;portrait&quot; is ignored. So are resizeableActivity=&quot;false&quot;, minAspectRatio, maxAspectRatio, and both setRequestedOrientation() and getRequestedOrientation(). The activity rotates with the device, resizes in split screen, and is recreated each time it happens.</p><p>Phones are untouched, because they sit below that threshold. A full pass on the phone rack says nothing at all about this change. It arrives on tablets, unfolded foldables and desktop windowing.</p><p>The visible damage is layout: a column of controls designed for 400dp, stretched across 1200. The expensive damage is state. An app that has been locked to portrait since 2019 has never needed to survive a configuration change, and the first rotation on a tablet takes whatever the user had typed with it.</p><h3>What is ignored, and where</h3><p>The threshold is sw600dp: displays with a smallest width of 600dp or more. On those, for an app targeting API 36, these no longer do anything:</p><ul><li>screenOrientation, for the values portrait, reversePortrait, sensorPortrait, userPortrait, landscape, reverseLandscape, sensorLandscape and userLandscape</li><li>resizeableActivity=&quot;false&quot;</li><li>minAspectRatio and maxAspectRatio</li><li>setRequestedOrientation() and getRequestedOrientation()</li></ul><p>Three exceptions survive. Displays under sw600dp behave as before, which is every phone. Games are exempt through the android:appCategory flag. And a user can opt an app back into its declared behaviour through the device&#39;s aspect-ratio settings, which is a user choice you do not control.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Dq4omoAE3e3a67vo-XswsQ.png" /></figure><h3>State goes first</h3><p>A portrait lock is also a test-coverage decision, taken years ago and rarely revisited. If an activity can never rotate, the recreate path never runs outside of a low-memory kill, and nobody notices that the draft, the scroll position and the half-filled form live in fields that do not survive it.</p><p>Forced resizability runs that path on a tablet every time the user turns the device, unfolds it, or drags the window to a different size.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gF4GMB8TCIGqBrvHFUDNhw.png" /></figure><p>Three storage choices, three different answers:</p><ul><li>A plain field, or remember in Compose, is <strong>lost</strong> on recreate.</li><li>A ViewModel <strong>survives recreate</strong> but not process death. It is the right place for loaded data and in-flight work.</li><li>rememberSaveable, onSaveInstanceState and SavedStateHandle <strong>survive both</strong>, because they go through the saved instance state Bundle. That Bundle is measured in kilobytes and crosses a Binder transaction, so it holds identifiers and user input, not lists or bitmaps.</li></ul><h3>Keeping state through a recreate</h3><p>In Compose, the selection and the text belong in rememberSaveable, and the loaded order belongs in the ViewModel:</p><pre>@Composable<br>fun AdaptiveOrderScreen(<br>    viewModel: OrderViewModel,<br>    modifier: Modifier = Modifier,<br>) {<br>    val order by viewModel.order.collectAsStateWithLifecycle()<br>    var note by rememberSaveable { mutableStateOf(&quot;&quot;) }<br>    var selectedLineId by rememberSaveable { mutableStateOf&lt;String?&gt;(null) }<br><br>    BoxWithConstraints(modifier = modifier.fillMaxSize()) {<br>        if (maxWidth &gt;= 600.dp) {<br>            Row(Modifier.fillMaxSize()) {<br>                OrderLines(<br>                    lines = order.lines,<br>                    selectedId = selectedLineId,<br>                    onSelect = { selectedLineId = it },<br>                    modifier = Modifier.weight(1f),<br>                )<br>                OrderDetail(<br>                    line = order.lines.firstOrNull { it.id == selectedLineId },<br>                    note = note,<br>                    onNoteChange = { note = it },<br>                    modifier = Modifier.weight(1f),<br>                )<br>            }<br>        } else {<br>            OrderLines(<br>                lines = order.lines,<br>                selectedId = selectedLineId,<br>                onSelect = { selectedLineId = it },<br>                modifier = Modifier.fillMaxSize(),<br>            )<br>        }<br>    }<br>}</pre><p>The ViewModel keeps the identifier of whatever it is loading in a SavedStateHandle, so a process death during a rotation does not land the user on an empty screen:</p><pre>class OrderViewModel(<br>    private val savedState: SavedStateHandle,<br>    private val repository: OrderRepository,<br>) : ViewModel() {<br><br>    private val orderId: String = checkNotNull(savedState[&quot;orderId&quot;])<br>    val order: StateFlow&lt;Order&gt; =<br>        repository.observeOrder(orderId)<br>            .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), Order.Empty)<br>}</pre><p>In a Views activity the same split is onSaveInstanceState for input and a ViewModel for data:</p><pre>class OrderActivity : AppCompatActivity() {<br><br>    // createSavedStateHandle() reads the intent extras, so the id survives<br>    // a process death that happens mid-rotation.<br>    private val viewModel: OrderViewModel by viewModels {<br>        viewModelFactory {<br>            initializer { OrderViewModel(createSavedStateHandle(), InMemoryOrderRepository) }<br>        }<br>    }<br>    private lateinit var binding: ActivityOrderBinding<br>    private var selectedLineId: String? = null<br><br>    override fun onCreate(savedInstanceState: Bundle?) {<br>        super.onCreate(savedInstanceState)<br>        binding = ActivityOrderBinding.inflate(layoutInflater)<br>        setContentView(binding.root)<br>        selectedLineId = savedInstanceState?.getString(KEY_SELECTED_LINE)<br>        val wideWindow = resources.configuration.screenWidthDp &gt;= 600<br>        binding.detailPane.isVisible = wideWindow<br>    }<br><br>    override fun onSaveInstanceState(outState: Bundle) {<br>        super.onSaveInstanceState(outState)<br>        outState.putString(KEY_SELECTED_LINE, selectedLineId)<br>    }<br><br>    private companion object {<br>        const val KEY_SELECTED_LINE = &quot;selected_line&quot;<br>    }<br>}</pre><p>screenWidthDp is read from the current Configuration, so it reports the window rather than the screen, and it updates when the window is resized in split screen.</p><h3>android:configChanges is not the fix</h3><p>Adding android:configChanges=&quot;orientation|screenSize|screenLayout&quot; stops the recreate, and every guide from the Android 13 era suggests it. It does not solve this. It transfers the relayout to you: the activity stays alive, the window changes size underneath it, and you now own re-measuring, re-inflating and reloading anything tied to width. The state bug does not disappear either. It moves to process death, where it is harder to reproduce and shows up as a crash report with no steps.</p><p>Handle the recreate instead. It is the path the framework tests.</p><h3>Stopping the layout from looking broken</h3><p>Full adaptive design is a bigger project than this deadline allows, and it is not what the change demands this week. The minimum is that nothing stretches absurdly: one width branch, as in the Compose sample above, between a single column and either a two-pane layout or a constrained-width column.</p><p>When there is time for the real version, the APIs to reach for are WindowSizeClass, currentWindowAdaptiveInfo and WindowMetricsCalculator. They express breakpoints and posture properly instead of hard-coding 600dp in two places.</p><h3>Camera previews break in a way layout tests miss</h3><p>Google’s own migration checklist singles this out: a viewfinder that assumes a fixed aspect ratio, or a fixed relationship to the sensor orientation, renders stretched or flipped once the activity can rotate freely. With CameraX, the preview use case follows the view, but output use cases do not — set ImageCapture.setTargetRotation when the display rotates, or photos come out sideways on exactly the devices this change affects.</p><h3>The opt-out, and its expiry date</h3><p>One activity can be held back:</p><pre>&lt;activity<br>    android:name=&quot;.LegacyScannerActivity&quot;<br>    android:screenOrientation=&quot;portrait&quot;&gt;<br>    &lt;property<br>        android:name=&quot;android.window.PROPERTY_COMPAT_ALLOW_RESTRICTED_RESIZABILITY&quot;<br>        android:value=&quot;true&quot; /&gt;<br>&lt;/activity&gt;</pre><p>It can also go on &lt;application&gt;, which is worse for the same reason as every app-wide opt-out: it hides the next regression behind the previous one.</p><p><strong>This one has a published end date.</strong> The property works while you target 36. Android 17 removes it, and for apps targeting API 37 the restrictions are always ignored on sw600dp displays. Using it buys one release cycle, and the work it defers is the same work, done later, under a deadline you no longer choose.</p><h3>Before you ship</h3><ul><li>An sw600dp+ emulator or tablet is in the test plan, not only phones</li><li>Every screen survives a rotation with its input intact: text fields, selection, scroll position</li><li>The ViewModel holds loaded data; the Bundle holds identifiers and input, nothing large</li><li>No new android:configChanges entries were added to silence the recreate</li><li>Camera and media screens were checked in both orientations</li><li>PROPERTY_COMPAT_ALLOW_RESTRICTED_RESIZABILITY appears only on named activities, each with a ticket dated before your API 37 bump</li><li>Dialogs, bottom sheets and anything measured in fixed dp were checked at 1200dp wide</li></ul><p>The rotation test is the one that pays for itself. Open each screen, type something, rotate, and look at what came back. On an app that has been portrait for years, the first three screens will tell you how much of this work is actually yours.</p><h3>Continue reading</h3><p><strong>[</strong><a href="https://medium.com/stackademic/onbackpressed-stops-being-called-when-you-target-android-16-0d091980c3d1"><strong>onBackPressed() Stops Being Called When You Target Android 16</strong></a><strong>]</strong> — the other targetSdk 36 change that fails without an error. If orientation caught you out, back handling is worth checking before your users find it.</p><p><em>Next in this series: edge-to-edge enforcement, the third of the targetSdk 36 changes that breaks quietly. Follow if you are partway through the same migration.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2e1b5b1e78fd" width="1" height="1" alt=""><hr><p><a href="https://blog.stackademic.com/screenorientation-is-ignored-when-you-target-android-16-2e1b5b1e78fd">screenOrientation Is Ignored When You Target Android 16</a> was originally published in <a href="https://blog.stackademic.com/">Stackademic</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[onBackPressed() Stops Being Called When You Target Android 16]]></title>
            <link>https://blog.stackademic.com/onbackpressed-stops-being-called-when-you-target-android-16-0d091980c3d1?source=rss-371517939594------2</link>
            <guid isPermaLink="false">https://medium.com/p/0d091980c3d1</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[jetpack-compose]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[YADNYESH RANA]]></dc:creator>
            <pubDate>Tue, 15 Sep 2026 10:32:37 GMT</pubDate>
            <atom:updated>2026-09-24T01:50:31.804Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yEOpnta2Rw7GsnxHkI-hhw.png" /></figure><p>If your app targets API 36 and runs on an Android 16 device, onBackPressed() is not called. KEYCODE_BACK is not dispatched to onKeyDown() either. Nothing crashes and nothing logs. Back simply does the platform default, which for most screens means the activity finishes.</p><p>That default is the bug. The “Discard changes?” dialog never appears, and the draft is gone. The in-app WebView closes instead of going back a page.</p><p>It gets past CI for a dull reason: the behaviour only changes on Android 16 and later. An Android 15 emulator runs your old override without complaint.</p><p>Swapping in the replacement API takes minutes. What breaks migrations is timing. The system now decides whether your app will handle back when the gesture <em>starts</em>, before any of your code runs. The old pattern of checking state and then deciding cannot be ported line by line.</p><h3>What stops running, and what still works</h3><p>Google Play has refused updates from apps below API 36 since 31 August 2026. Teams with an extension have until 1 November. Either way, this change is arriving this quarter.</p><p>For an app targeting API 36 on Android 16, these no longer receive back:</p><ul><li>an onBackPressed() override in an Activity or Dialog</li><li>onKeyDown() or dispatchKeyEvent() checking for KeyEvent.KEYCODE_BACK</li></ul><p>These do:</p><ul><li>OnBackPressedCallback, registered on onBackPressedDispatcher</li><li>OnBackInvokedCallback, the platform API underneath it</li><li>Compose BackHandler and PredictiveBackHandler</li></ul><p>None of the working ones are new. ComponentActivity.onBackPressed() has carried a deprecation warning since androidx.activity 1.9.0. In 1.12.0 the dispatcher was rebuilt on top of the androidx.navigationevent library, so OnBackPressedCallback is a maintained API, not a compatibility shim. API 36 is simply where the warning became behaviour.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2-vBz3rtNNCgNMYm41AVcw.png" /></figure><h3>Why a line-by-line port breaks</h3><p>Most codebases have this override in some form:</p><pre>override fun onBackPressed() {<br>    if (viewModel.hasUnsavedChanges.value) {<br>        showDiscardDialog()<br>    } else {<br>        super.onBackPressed()<br>    }<br>}</pre><p>The obvious port registers an always-enabled callback and moves the if inside. When there is nothing to guard, the callback disables itself and re-dispatches:</p><pre>onBackPressedDispatcher.addCallback(this) {<br>    if (viewModel.hasUnsavedChanges.value) {<br>        showDiscardDialog()<br>    } else {<br>        isEnabled = false<br>        onBackPressedDispatcher.onBackPressed()<br>    }<br>}</pre><p>It compiles. The dialog appears when it should and the screen closes when it should. It still has two bugs, and the old override had neither.</p><p>The first is the gesture. With predictive back, the moment a finger starts the swipe, the system asks one question: is any callback enabled? If one is, the app owns the gesture and the system does not play its back-to-home or cross-activity preview. This callback answers yes on every swipe, including the ones where it is about to hand the event straight back. The user drags, sees nothing move, and then the screen closes anyway.</p><p>The second is quieter. isEnabled = false is never undone. Save, edit again, press back, and the new draft is gone without a dialog.</p><p>Google’s predictive back guide describes the pattern exactly: conditional back logic means you are “reacting to the back event after it has already occurred.”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zlV6mz8pUn-FvfQuRqXCzQ.png" /></figure><p>So one rule covers everything below: <strong>know before the gesture starts.</strong> A callback’s isEnabled must already say whether this screen would intercept back, and it must be updated every time that answer changes.</p><h3>Views: drive isEnabled from state</h3><p>The ViewModel exposes the answer as a StateFlow:</p><pre>val hasUnsavedChanges: StateFlow&lt;Boolean&gt; =<br>    combine(savedText, draftText) { saved, current -&gt; saved != current }<br>        .stateIn(viewModelScope, SharingStarted.Eagerly, false)</pre><p>The activity keeps the callback in step with it:</p><pre>class EditorActivity : AppCompatActivity() {<br><br>private val viewModel: EditorViewModel by viewModels()<br>    // Starts disabled: a clean editor has no reason to intercept back.<br>    private val discardChangesCallback = object : OnBackPressedCallback(false) {<br>        override fun handleOnBackPressed() {<br>            showDiscardDialog()<br>        }<br>    }<br>    override fun onCreate(savedInstanceState: Bundle?) {<br>        super.onCreate(savedInstanceState)<br>        setContentView(R.layout.activity_editor)<br>        onBackPressedDispatcher.addCallback(this, discardChangesCallback)<br>        lifecycleScope.launch {<br>            repeatOnLifecycle(Lifecycle.State.STARTED) {<br>                viewModel.hasUnsavedChanges.collect { dirty -&gt;<br>                    discardChangesCallback.isEnabled = dirty<br>                }<br>            }<br>        }<br>    }<br>    private fun showDiscardDialog() {<br>        MaterialAlertDialogBuilder(this)<br>            .setTitle(&quot;Discard changes?&quot;)<br>            .setPositiveButton(&quot;Discard&quot;) { _, _ -&gt;<br>                viewModel.discardChanges()<br>                // Disable now; the flow&#39;s update is not guaranteed to land first.<br>                discardChangesCallback.isEnabled = false<br>                onBackPressedDispatcher.onBackPressed()<br>            }<br>            .setNegativeButton(&quot;Keep editing&quot;, null)<br>            .show()<br>    }<br>}</pre><p><em>Look at the Discard branch.</em> discardChanges() will flip the flow to false too, but stateIn delivers that on a later dispatch, and onBackPressed() runs on the very next line. If the callback were still enabled, the re-dispatch would land back in handleOnBackPressed() and show the dialog a second time. With it disabled, the dispatcher finds no enabled callback and finishes the activity.</p><p>The flow also fixes the second bug from the naive port. Type one character after saving and the collector turns the callback back on.</p><h3>Compose: compose BackHandler every time</h3><pre>@Composable<br>fun EditorScreen(<br>    viewModel: EditorViewModel,<br>    onExit: () -&gt; Unit,<br>    modifier: Modifier = Modifier,<br>) {<br>    val draft by viewModel.draft.collectAsStateWithLifecycle()<br>    val hasUnsavedChanges by viewModel.hasUnsavedChanges.collectAsStateWithLifecycle()<br>    var showDiscardDialog by remember { mutableStateOf(false) }<br><br>    // Always composed. The enabled flag, not an if, decides whether it intercepts.<br>    BackHandler(enabled = hasUnsavedChanges) {<br>        showDiscardDialog = true<br>    }<br>    OutlinedTextField(<br>        value = draft,<br>        onValueChange = viewModel::onDraftChanged,<br>        modifier = modifier.fillMaxSize().padding(16.dp),<br>    )<br>    if (showDiscardDialog) {<br>        AlertDialog(<br>            onDismissRequest = { showDiscardDialog = false },<br>            title = { Text(&quot;Discard changes?&quot;) },<br>            confirmButton = {<br>                TextButton(onClick = {<br>                    showDiscardDialog = false<br>                    viewModel.discardChanges()<br>                    onExit()<br>                }) { Text(&quot;Discard&quot;) }<br>            },<br>            dismissButton = {<br>                TextButton(onClick = { showDiscardDialog = false }) { Text(&quot;Keep editing&quot;) }<br>            },<br>        )<br>    }<br>}</pre><p>The version to avoid wraps the handler in a condition: if (hasUnsavedChanges) { BackHandler { showDiscardDialog = true } }. Back handlers are ordered by registration, and the most recently composed one wins. Every time that condition flips back to true, the handler is composed again and becomes the newest. It jumps ahead of a handler that should have taken the event first, such as a bottom sheet open on top of the editor.</p><p>The androidx.activity docs now say this outright: compose BackHandler unconditionally and switch it with enabled. It is the same rule as the Views version, expressed as state.</p><h3>WebView: the regression users notice first</h3><p>An embedded browser that exits on back instead of returning to the previous page is the version of this bug users notice first. The old fix was two lines in onBackPressed(). The new one makes canGoBack() the callback&#39;s state:</p><pre>class ArticleActivity : AppCompatActivity() {<br><br>private lateinit var webView: WebView<br>    private val webBackCallback = object : OnBackPressedCallback(false) {<br>        override fun handleOnBackPressed() {<br>            webView.goBack()<br>        }<br>    }<br>    override fun onCreate(savedInstanceState: Bundle?) {<br>        super.onCreate(savedInstanceState)<br>        webView = WebView(this)<br>        setContentView(webView)<br>        webView.webViewClient = object : WebViewClient() {<br>            override fun doUpdateVisitedHistory(view: WebView, url: String?, isReload: Boolean) {<br>                super.doUpdateVisitedHistory(view, url, isReload)<br>                webBackCallback.isEnabled = view.canGoBack()<br>            }<br>        }<br>        onBackPressedDispatcher.addCallback(this, webBackCallback)<br>        webView.loadUrl(&quot;https://developer.android.com&quot;)<br>    }<br>}</pre><p>doUpdateVisitedHistory fires on every navigation, including the goBack() the callback itself triggers. When the user reaches the first page, the flag drops to false, and the next swipe leaves the screen with the system preview intact.</p><h3>Observing back without consuming it</h3><p>Some onBackPressed() overrides never intercepted anything. They logged an event and called super. Porting that to an enabled OnBackPressedCallback takes over every swipe for a log line, and on the root screen it switches off the back-to-home preview.</p><p>Android 16 adds a priority for exactly this:</p><pre>class HomeActivity : AppCompatActivity() {<br><br>override fun onCreate(savedInstanceState: Bundle?) {<br>        super.onCreate(savedInstanceState)<br>        setContentView(R.layout.activity_home)<br>        if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.BAKLAVA) {<br>            observeBackNavigation()<br>        }<br>    }<br>    @RequiresApi(Build.VERSION_CODES.BAKLAVA)<br>    private fun observeBackNavigation() {<br>        onBackInvokedDispatcher.registerOnBackInvokedCallback(<br>            OnBackInvokedDispatcher.PRIORITY_SYSTEM_NAVIGATION_OBSERVER<br>        ) {<br>            Log.i(&quot;Navigation&quot;, &quot;Back pressed on home screen&quot;)<br>        }<br>    }<br>}</pre><p>An observer is told about the event without taking it, so the system animation still plays. The constant only exists on Android 16 and later, which is why the version check sits outside the function rather than inside it. Below Android 16 there is no observer priority, so decide whether that log line is worth breaking the gesture for.</p><h3>The temporary escape hatch</h3><p>If one screen cannot be migrated this sprint, it can keep the old behaviour:</p><pre>&lt;activity<br>    android:name=&quot;.LegacyCheckoutActivity&quot;<br>    android:enableOnBackInvokedCallback=&quot;false&quot; /&gt;</pre><p>Put it on the activity, not on &lt;application&gt;. Set app-wide, it switches the new behaviour off for every screen you have already migrated. That hides the next regression the same way the Android 15 emulator hid this one. Google&#39;s Android 16 behaviour-change notes call the attribute a temporary opt-out, so give it a ticket with a due date.</p><h3>Before you ship</h3><p>One search finds most of the dead code:</p><pre>grep -rnE &quot;override fun onBackPressed|void onBackPressed\(|KEYCODE_BACK&quot; --include=*.kt --include=*.java .</pre><ul><li>Every onBackPressed() override and KEYCODE_BACK check is replaced or deleted</li><li>Each callback’s isEnabled comes from state, never from a check inside handleOnBackPressed()</li><li>Compose BackHandlers are always composed and switched with enabled</li><li>A callback that disables itself is re-enabled when its state changes back</li><li>enableOnBackInvokedCallback=&quot;false&quot; appears only on named activities, each with a ticket</li><li>Tested on an Android 16 device or emulator by swiping back, not only by tapping</li></ul><p>The last item is the one that catches all of it. Every bug above is invisible below Android 16, and a stuck predictive back preview only shows up under a real swipe. One pass on an API 36 image finds what every run on the API 35 image in CI keeps missing.</p><p><em>This is the first of the targetSdk 36 changes that fail without an error. Edge-to-edge enforcement and the large-screen orientation override come next. Follow if you are partway through the same migration.</em></p><h3>Before you go</h3><ul><li>Please take a moment to like the post and follow the writer!</li><li>Did you know that over 400,000 developers share what they’re building, learning, and discovering across our platforms every month? Learn how you can contribute <a href="https://plainenglish.io/write-for-us"><strong>here</strong></a><strong>.</strong></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0d091980c3d1" width="1" height="1" alt=""><hr><p><a href="https://blog.stackademic.com/onbackpressed-stops-being-called-when-you-target-android-16-0d091980c3d1">onBackPressed() Stops Being Called When You Target Android 16</a> was originally published in <a href="https://blog.stackademic.com/">Stackademic</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SafetyNetClient.attest() Has Been Failing Since January 2025]]></title>
            <link>https://blog.stackademic.com/safetynet-is-gone-migrating-to-the-play-integrity-api-in-kotlin-f812baf155d7?source=rss-371517939594------2</link>
            <guid isPermaLink="false">https://medium.com/p/f812baf155d7</guid>
            <category><![CDATA[mobile-security]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[kotlin]]></category>
            <dc:creator><![CDATA[YADNYESH RANA]]></dc:creator>
            <pubDate>Sun, 06 Sep 2026 08:13:54 GMT</pubDate>
            <atom:updated>2026-10-08T19:40:00.798Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mmaDE7CTLs6-Wnyk0d4uQw.png" /></figure><p>SafetyNet Attestation stopped returning verdicts on 31 January 2025. If SafetyNetClient.attest() is still sitting in your codebase, it has not been protecting anything for over a year. It has been failing — and depending on how you wrote the error branch, quite possibly failing open.</p><p>The client-side replacement is about ten lines of Kotlin. That part is easy, and it is where most migration guides stop. The two things that actually break migrations are where you verify the token, and whether you bound it to the request it was minted for. Both live on the server. Both are invisible to a code review that only reads the app.</p><blockquote>The whole SafetyNet family is retired, not just attestation. If verifyWithRecaptcha() is also sitting in your codebase, check its status too — this article covers the attestation half, which is the part Play Integrity replaced.</blockquote><h3>What actually changed</h3><p>Three dates worth having:</p><p>Google announced the deprecation in June 2022. New developer onboarding closed on 31 January 2023. The full turndown landed on 31 January 2025 — after that date the API stops handing back verdicts entirely.</p><p>Play Integrity carries every signal SafetyNet Attestation had, plus Google Play licensing and error messaging that tells you why a request failed instead of just that it did. It also introduced something SafetyNet never had: two request modes. Most migration content on the internet predates the newer of the two, which means the default path it teaches is the slower and more quota-constrained one.</p><h3>Standard or classic — decide before you write code</h3><p>StandardClassicLatencya few hundred msa few secondsAssessmenton-device cache, refreshed by Playfresh on every callQuotabuilt for per-action usetightly rate-limitedReplay defencerequestHash + Play-side mitigationentirely yoursBattery and datalownoticeably higher</p><p>If you are guarding a user action — a transfer, a voucher redemption, a signup — you want standard requests. Classic exists for the narrower case where you truly need an uncached assessment and can absorb both the latency and the quota ceiling.</p><p>This matters more than it sounds. A migration that swaps attest() for a classic request is technically correct and operationally worse than the thing it replaced: same protection, several seconds of added latency on your most important flows, and a rate limit you will meet on your busiest day.</p><h3>The client side</h3><p>Standard requests split into two phases. The warm-up talks to Google’s servers and is the slow part. The per-action request does not, which is what makes it usable inside a click handler.</p><pre>class IntegrityGate(<br>    context: Context,<br>    private val cloudProjectNumber: Long,<br>) {<br>    private val manager = IntegrityManagerFactory.createStandard(<br>        context.applicationContext<br>    )<br>    private var provider: StandardIntegrityTokenProvider? = null<br><br>    /** Call once, early. Hits the network - keep it off the critical path. */<br>    suspend fun warmUp() {<br>        provider = manager.prepareIntegrityToken(<br>            PrepareIntegrityTokenRequest.builder()<br>                .setCloudProjectNumber(cloudProjectNumber)<br>                .build()<br>        ).await()<br>    }<br>    /** Call per protected action. [requestHash] binds the token to this action. */<br>    suspend fun tokenFor(requestHash: String): String {<br>        val ready = provider ?: error(&quot;warmUp() has not completed&quot;)<br>        return ready.request(<br>            StandardIntegrityTokenRequest.builder()<br>                .setRequestHash(requestHash)<br>                .build()<br>        ).await().token()<br>    }<br>}</pre><p>await() comes from kotlinx-coroutines-play-services. Without it you are back to nesting addOnSuccessListener blocks, which is how the warm-up ends up accidentally inside the button handler.</p><p>Call warmUp() at app start or when the user enters the protected area — not when they tap the button. The provider is reusable and worth refreshing periodically rather than per action.</p><h3>Verify on your server, never on the device</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cAszDcflcqWO1J7mQJkiMw.png" /></figure><p>The token that comes back is an encrypted blob. It is meant to be decoded by your backend, which calls Google’s servers to do it. That path exists precisely so the decode never has to happen on the handset.</p><p>Decoding on the device defeats the entire mechanism — including the version of this you might be tempted by, where you “just do a quick local check before bothering the server.” An attacker who controls the device controls whatever branch you write after that decode. They do not need to forge a verdict; they need to change the if. The verdict is only worth something when it is read on a machine the attacker does not own.</p><pre>// Server side. The device never sees this code.<br>val payload = playIntegrity<br>    .decodeIntegrityToken(<br>        packageName,<br>        DecodeIntegrityTokenRequest().setIntegrityToken(token)<br>    )<br>    .execute()<br>    .tokenPayloadExternal<br><br>val request = payload.requestDetails<br>val device = payload.deviceIntegrity<br>require(request.requestPackageName == packageName)<br>require(request.requestHash == expectedHash)<br>require(abs(System.currentTimeMillis() - request.timestampMillis) &lt; 60_000)</pre><p>Those three require calls are cheap, and in my experience reviewing this kind of migration, the middle one is the one that is missing.</p><h3>requestHash, or your token is replayable</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O4_tMPPTH4kvAJz2BmK3pg.png" /></figure><p>This is the failure that survives code review and shows up in production.</p><p>A token with no requestHash makes a narrow claim: this app, on this device, is genuine, at this time. It says nothing about what the user was doing. So capture a token minted when the user opened their balance screen, replay it against the transfer endpoint, and your server sees a valid token from a genuine device on a recent timestamp — and approves.</p><p>Nothing about that attack requires breaking the attestation. It requires only that you never told the token what it was for.</p><p>requestHash closes the gap. You hash the parameters of the specific action, hand it over when requesting the token, and Google echoes it back inside the signed payload where the client cannot touch it. Your server recomputes the hash from the request it actually received and compares the two.</p><pre>fun requestHash(vararg parts: String): String =<br>    MessageDigest.getInstance(&quot;SHA-256&quot;)<br>        .digest(parts.joinToString(&quot;|&quot;).toByteArray())<br>        .joinToString(&quot;&quot;) { &quot;%02x&quot;.format(it) }<br><br>// At the call site - include everything that defines the action.<br>val hash = requestHash(userId, &quot;TRANSFER&quot;, amountMinor.toString(), serverNonce)<br>val token = integrityGate.tokenFor(hash)<br>api.transfer(amountMinor, serverNonce, token)</pre><p>Include the server-issued nonce. A hash over only the user’s own parameters is still replayable by the user against themselves — the same transfer, submitted twice.</p><h3>Reading the verdict without over-blocking</h3><p>deviceRecognitionVerdict is a list, not an enum, and it can be empty:</p><ul><li>MEETS_STRONG_INTEGRITY — hardware-backed, recent Android, boot verified</li><li>MEETS_DEVICE_INTEGRITY — a Play-certified device in good standing</li><li>MEETS_BASIC_INTEGRITY — plausible device, weaker signals</li><li>empty — emulator, or something that satisfied nothing</li></ul><p>The migration mistake here is mapping everything below device integrity to a hard block. Basic-integrity-only devices include real customers on some OEM builds and older hardware. Block them and you have converted a security control into a support queue, which is a trade most teams would not make deliberately.</p><pre>val verdicts = device.deviceRecognitionVerdict.orEmpty()<br><br>val decision = when {<br>    &quot;MEETS_STRONG_INTEGRITY&quot; in verdicts -&gt; Decision.ALLOW<br>    &quot;MEETS_DEVICE_INTEGRITY&quot; in verdicts -&gt; Decision.ALLOW<br>    &quot;MEETS_BASIC_INTEGRITY&quot; in verdicts  -&gt; Decision.STEP_UP<br>    else                                 -&gt; Decision.REVIEW<br>}</pre><p>Step-up is the useful middle: a second factor, a lower transaction ceiling, a short delay. It keeps the legitimate long tail while making the attacker’s path expensive. A binary allow/deny throws away most of what the verdict is telling you.</p><h3>Before you ship</h3><ul><li>play-services-safetynet is gone from your dependency graph</li><li>The cloud project number matches the project linked in Play Console</li><li>warmUp() runs off the critical path, and its failure is handled</li><li>Every protected action computes its own requestHash, including a server nonce</li><li>The server rejects on package mismatch, hash mismatch, or a stale timestamp</li><li>Basic integrity is graded, not blocked</li><li>The error path fails closed — a missing verdict is not a passing verdict</li></ul><p>That last one is worth sitting with. The most common way this migration goes wrong is not a forged token. It is a try/catch that swallows a network failure and lets the request through, written by someone who reasonably did not want an outage at Google to take down checkout. Decide that trade deliberately, and write down which way you chose.</p><h3>Continue reading</h3><p><a href="https://medium.com/quick-code/using-googles-safetynet-recaptcha-api-with-android-48e2cf12f370"><strong>Using Google’s SafetyNet reCAPTCHA API with Android</strong></a> — the other half of the SafetyNet family. If verifyWithRecaptcha() is still anywhere in your codebase, it is on the road attest() already reached the end of.</p><p><a href="https://medium.com/@yadnyesh_rana/mastering-coroutines-in-android-development-with-kotlin-3a42e668f23c"><strong>Mastering Coroutines in Android Development with Kotlin</strong> </a>— the await() bridge the client code above leans on, if kotlinx-coroutines-play-services is new to you.</p><h3>Before you go</h3><ul><li>Please take a moment to like the post and follow the writer!</li><li>Did you know that over 400,000 developers share what they’re building, learning, and discovering across our platforms every month? Learn how you can contribute <a href="https://plainenglish.io/write-for-us"><strong>here</strong></a>.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f812baf155d7" width="1" height="1" alt=""><hr><p><a href="https://blog.stackademic.com/safetynet-is-gone-migrating-to-the-play-integrity-api-in-kotlin-f812baf155d7">SafetyNetClient.attest() Has Been Failing Since January 2025</a> was originally published in <a href="https://blog.stackademic.com/">Stackademic</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Compose Abstractions We Deleted From Our Codebase]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/@yadnyesh_rana/the-compose-abstractions-we-deleted-from-our-codebase-6b46656f52b9?source=rss-371517939594------2"><img src="https://cdn-images-1.medium.com/max/1536/1*RpwdQzfz5vQkO32dzoG9sg.png" width="1536"></a></p><p class="medium-feed-snippet">We used to think a good Android codebase was one where almost everything was reusable.</p><p class="medium-feed-link"><a href="https://medium.com/@yadnyesh_rana/the-compose-abstractions-we-deleted-from-our-codebase-6b46656f52b9?source=rss-371517939594------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@yadnyesh_rana/the-compose-abstractions-we-deleted-from-our-codebase-6b46656f52b9?source=rss-371517939594------2</link>
            <guid isPermaLink="false">https://medium.com/p/6b46656f52b9</guid>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[mobile-development]]></category>
            <category><![CDATA[jetpack-compose]]></category>
            <category><![CDATA[android-development]]></category>
            <category><![CDATA[kotlin]]></category>
            <dc:creator><![CDATA[YADNYESH RANA]]></dc:creator>
            <pubDate>Sun, 09 Aug 2026 12:46:20 GMT</pubDate>
            <atom:updated>2026-08-09T12:46:20.181Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[We Regretted Making Everything Reusable in Compose]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/codetodeploy/we-regretted-making-everything-reusable-in-compose-a396a8d418d1?source=rss-371517939594------2"><img src="https://cdn-images-1.medium.com/max/1536/1*Fz6YilN0EIJqET8mlW5EPg.png" width="1536"></a></p><p class="medium-feed-snippet">One of the biggest surprises after moving to Jetpack Compose wasn&#x2019;t performance.</p><p class="medium-feed-link"><a href="https://medium.com/codetodeploy/we-regretted-making-everything-reusable-in-compose-a396a8d418d1?source=rss-371517939594------2">Continue reading on CodeToDeploy »</a></p></div>]]></description>
            <link>https://medium.com/codetodeploy/we-regretted-making-everything-reusable-in-compose-a396a8d418d1?source=rss-371517939594------2</link>
            <guid isPermaLink="false">https://medium.com/p/a396a8d418d1</guid>
            <category><![CDATA[mobile-development]]></category>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[jetpack-compose]]></category>
            <category><![CDATA[android-development]]></category>
            <dc:creator><![CDATA[YADNYESH RANA]]></dc:creator>
            <pubDate>Mon, 20 Jul 2026 18:28:03 GMT</pubDate>
            <atom:updated>2026-08-15T06:00:21.741Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Why Most Compose Teams End Up With a God ViewModel]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/codetodeploy/why-most-compose-teams-end-up-with-a-god-viewmodel-c6623e744ece?source=rss-371517939594------2"><img src="https://cdn-images-1.medium.com/max/1536/1*mC_LL0nCEF5ua2RgP2Tmug.png" width="1536"></a></p><p class="medium-feed-snippet">A few weeks ago, I reviewed a pull request that added a fairly simple feature.</p><p class="medium-feed-link"><a href="https://medium.com/codetodeploy/why-most-compose-teams-end-up-with-a-god-viewmodel-c6623e744ece?source=rss-371517939594------2">Continue reading on CodeToDeploy »</a></p></div>]]></description>
            <link>https://medium.com/codetodeploy/why-most-compose-teams-end-up-with-a-god-viewmodel-c6623e744ece?source=rss-371517939594------2</link>
            <guid isPermaLink="false">https://medium.com/p/c6623e744ece</guid>
            <category><![CDATA[android-development]]></category>
            <category><![CDATA[mobile-development]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[jetpack-compose]]></category>
            <category><![CDATA[software-architecture]]></category>
            <dc:creator><![CDATA[YADNYESH RANA]]></dc:creator>
            <pubDate>Tue, 16 Jun 2026 07:22:07 GMT</pubDate>
            <atom:updated>2026-06-19T03:59:49.404Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Why Most Compose Teams Create Too Many ViewModels]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/codetodeploy/why-most-compose-teams-create-too-many-viewmodels-d65af5ee22a9?source=rss-371517939594------2"><img src="https://cdn-images-1.medium.com/max/1536/1*BvfXhx7r4QoHHD3EWN1PHg.png" width="1536"></a></p><p class="medium-feed-snippet">A few years ago, I thought creating more ViewModels was a sign of good architecture.</p><p class="medium-feed-link"><a href="https://medium.com/codetodeploy/why-most-compose-teams-create-too-many-viewmodels-d65af5ee22a9?source=rss-371517939594------2">Continue reading on CodeToDeploy »</a></p></div>]]></description>
            <link>https://medium.com/codetodeploy/why-most-compose-teams-create-too-many-viewmodels-d65af5ee22a9?source=rss-371517939594------2</link>
            <guid isPermaLink="false">https://medium.com/p/d65af5ee22a9</guid>
            <category><![CDATA[mobile-development]]></category>
            <category><![CDATA[android-development]]></category>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[jetpack-compose]]></category>
            <dc:creator><![CDATA[YADNYESH RANA]]></dc:creator>
            <pubDate>Thu, 11 Jun 2026 05:31:00 GMT</pubDate>
            <atom:updated>2026-06-19T04:12:43.407Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Why Most Compose State Management Becomes Unmanageable]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/codetodeploy/why-most-compose-state-management-becomes-unmanageable-4571a22279ed?source=rss-371517939594------2"><img src="https://cdn-images-1.medium.com/max/1536/1*eZ9agpifLkDi0O_0nQ3n0w.png" width="1536"></a></p><p class="medium-feed-snippet">When our team first started migrating screens to Jetpack Compose, everything felt easier.</p><p class="medium-feed-link"><a href="https://medium.com/codetodeploy/why-most-compose-state-management-becomes-unmanageable-4571a22279ed?source=rss-371517939594------2">Continue reading on CodeToDeploy »</a></p></div>]]></description>
            <link>https://medium.com/codetodeploy/why-most-compose-state-management-becomes-unmanageable-4571a22279ed?source=rss-371517939594------2</link>
            <guid isPermaLink="false">https://medium.com/p/4571a22279ed</guid>
            <category><![CDATA[jetpack-compose]]></category>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[android-development]]></category>
            <dc:creator><![CDATA[YADNYESH RANA]]></dc:creator>
            <pubDate>Mon, 08 Jun 2026 05:31:00 GMT</pubDate>
            <atom:updated>2026-06-17T05:33:21.871Z</atom:updated>
        </item>
    </channel>
</rss>