Android开发常识

如何才算是后台应用?除了下面情况外都是后台应用

1. 具有可见的Activity

2. 具有前台服务

3. 另一个前台应用已关联到该应用(通过bindService或者使用该应用的ContentProvider)。


当应用处于后台时:

1.在后台运行的服务在几分钟内会被stop掉(模拟器测试在1分钟左右后被kill掉)。在这段时间内,应用仍可以创建和使用服务。

2.在应用处于后台几分钟后(模拟器测试1分钟左右),应用将不能再通过startService创建后台服务,如果创建则抛出以下异常

Caused by: java.lang.IllegalStateException: Not allowed to start service Intent { cmp=com.example.samsung.test/.TestService }: app is in background

应用处于后台时,虽然不能通过startService创建后台服务,但仍可以通过下面的方式创建前台服务。

    NotificationManager noti = (NotificationManager)getApplicationContext().getSystemService(NOTIFICATION_SERVICE);
    noti.startServiceInForeground();

后台服务会被kill掉,官方推荐可使用AlarmManager、SyncAdapter、JobScheduler代替后台服务。
用户sharepreference数据记录在

/data/user_de/0/com.android.settings/shared_prefs

强制本地同步服务器代码

repo forall -c "git clean -fd;git reset --hard";repo sync -j4 -cd;

./repo forall -c "git clean -fd ; git reset --hard"; ./repo sync -j8 -dc; ./repo sync -j8 -dc;

repo forall -c 'git reset --hard' # Remove all working directory (and staged) changes.
repo forall -c 'git clean -f -d' # Clean untracked files

远程的P2P设备会有两种模式:

    1)、Target:当前手机往外发送数据的时候,远程的设备就是Target,自己就是Initiator

    2)、Initiator:当前手机接受数据的时候,远程的设备就是Initiator,自己就是Target.

dumpsys activity top

dumpsys window windows |grep "current"

LOCAL_MODULE := SettingsProvider--->模块名---->make 模块名
LOCAL_PACKAGE_NAME := SettingsProvider--->make packagename

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值