0

Is it possible to attach the Android debugger of Android Studio again in order to check Break point after app has been closed ?

Robert
  • 39,162
  • 17
  • 99
  • 152
Sudhanshu Gaur
  • 7,486
  • 9
  • 47
  • 94

2 Answers2

1

You may be able to attach a debugger if the app process is invisible but still alive. If a process is terminated or not is up to the Android OS.

However you will not be able to "check" a breakpoint as breakpoint only work if the code the breakpoint is contained is executed. Breakpoints therefore only work interactively - if you attach to a process after a breakpoint has been passed it is impossible to extract information regarding the process state (variables, ..) at the time the breakpoint was passed, because it is no longer available.

Robert
  • 39,162
  • 17
  • 99
  • 152
  • I have added the breakpoint in my Firebase Listener Service(When I receive a push notification and my app is closed) – Sudhanshu Gaur May 09 '18 at 17:09
  • @Sudhanshu Gaur Ok, then your real question is this, right? [How to debug an Android service](https://stackoverflow.com/questions/4008081)? See also [Breakpoints not working with a service in Android](https://stackoverflow.com/questions/32302630) – Robert May 09 '18 at 17:42
  • I tried your above link with `sync` parameter, but the thing is as my service class is MyFcmListener Service so this service will run just for a milliseconds and because of which when I will attach my process in debug this service will not get shown. – Sudhanshu Gaur May 09 '18 at 19:17
  • 1
    @Sudhanshu Gaur: Then try waitForDebugger and/or other ways to to delay the service so that you can attach. Or use the good old `Log` debugging (print everything you might want to know and every branch). – Robert May 10 '18 at 16:41
  • `waitForDebugger` worked I was doing something wrong previous time. Thanks :) – Sudhanshu Gaur May 10 '18 at 17:06
1

You are probably trying to open the app from a notification or service when your app is closed or has been removed from the background by the Android system.

Here is a nice workaround for that.

Make a new class named Notification.class and extend Application class to it as shown below.

package com.example.app;

import android.app.Application;

public class Notification extends Application {

    @Override
    public void onCreate() {
        super.onCreate();

    }
}

After this, in your AndroidManifest.xml file, make the following changes.

<application
    android:name=".NotificationClass"
    .
    .  
    android:usesCleartextTraffic="true">
</application>

After this whenever you receive a notification for your app and your app is not in background or foreground, you will be able to attach the debugger from Android Studio before clicking on the notification.

Hope it helps. :)

Anubhav Mittal
  • 427
  • 3
  • 7