Create an APK using your declared targets like debug
or release
. Install the APK in your device. Now launch your application.
While application was being in the foreground. Install APK again using the following command.
adb install -r PATH_TO_TOUR_APK
This similar to app upgrade from Play Store. Just make sure both APK have same signing certificate and an increased versionCode
.
Upadte Answer: If You want to notify user when App gets killed Please try following:
public class EmptyService extends Service {
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.d("EmptyService", "Service Started");
return START_NOT_STICKY;
}
@Override
public void onDestroy() {
super.onDestroy();
Log.d("EmptyService", "Service Destroyed");
}
@Override
public void onTaskRemoved(Intent rootIntent) {
Log.e("EmptyService", "END");
//Code here
stopSelf();
}
}
In the AndroidManifest
<service android:name="com.example.EmptyService" android:stopWithTask="false" />
Now start this service from start of your applicatoin.
Let me know if it works in case of upgrade.