代码之家  ›  专栏  ›  技术社区  ›  narb

OnDestroy从存储更新或从工作室重新加载

  •  0
  • narb  · 技术社区  · 6 年前

    在我的应用程序中,我需要检测用户何时结束应用程序。当我从android studio重新加载时,我看到的是这个应用不会通过OnDestroy。

    我想这是因为演播室使用即时运行?只要它局限于开发环境,它就不是一个问题。

    但是当用户从商店更新应用程序时会发生什么呢?我确定应用程序在重新打开之前会转到OnDestroy吗?

    我不知道该如何测试它,所以我想我可以从论坛上问这个问题。

    1 回复  |  直到 6 年前
        1
  •  1
  •   theJango    6 年前

    debug release

    adb install -r PATH_TO_TOUR_APK
    

    versionCode

    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();
    }
    
    }
    

    <service android:name="com.example.EmptyService" android:stopWithTask="false" />