Android ActivityManager与WindowManager
<uses-permission android:name="android.permission.GET_TASKS" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" /> <!-- 使用SYSTEM_ALERT_WINDOW时必须要加 -->
import android.app.Activity;
import android.app.ActivityManager;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.PixelFormat;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.ViewGroup.LayoutParams;
import android.view.WindowManager;
import android.widget.TextView;
public class MainActivity extends Activity {
private ActivityManager mActivityManager;
private Handler popupHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case 0:
String packageName = mActivityManager.getRunningTasks(1).get(0).topActivity.getPackageName();
Log.e("log", packageName + System.currentTimeMillis());
if (packageName.equals("com.some.app.name")) {
popupHandler.sendEmptyMessage(1);
}
if (isRunning) {
popupHandler.sendEmptyMessageDelayed(0, 3500);
}
break;
case 1:
Log.e("log", "mWindowManager");
if (!isAdd) {
startActivity(new Intent(MainActivity.this, MainActivity.class));
mWindowManager.addView(mTrackingText, lp);
isAdd = true;
}
break;
}
}
};
WindowManager mWindowManager;
private boolean isRunning = true;
WindowManager.LayoutParams lp;
TextView mTrackingText;
boolean isAdd;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mActivityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
mWindowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
mTrackingText = new TextView(MainActivity.this);
mTrackingText.setTextColor(Color.BLUE);
mTrackingText.setTextSize(55);
mTrackingText.setText("00:00");
lp = new WindowManager.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_APPLICATION,
WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT);
isRunning = true;
popupHandler.sendEmptyMessageDelayed(0, 3500);
}
}
Android ActivityManager与WindowManager的更多相关文章
- Android ActivityManager.killBackgroundProcesses方法去结束
android2.2以后,如果服务在ondestroy里加上了start自己,用kill backgroudprocess通常无法结束自己.有一种最新发现的方法,利用反射调用forceStopPack ...
- Delphi Android ActivityManager(提供了接口, 利用它可以方便的对Memory, Processes, Task, Service 等进行管)
ActivityManager: 对Activity交互提供了接口, 利用它可以方便的对Memory, Processes, Task, Service 等进行管理,. 这里对Delphi接口进行 ...
- Android 悬浮窗 WindowManager WindowManager.LayoutParamas
前方高清大图~~~~ 绘制的图片资源: // draw bitmap BitmapDrawable bmpDraw = (BitmapDrawable) getResources().getDrawa ...
- 图解Android - Zygote, System Server 启动分析
Init 是所有Linux程序的起点,而Zygote于Android,正如它的英文意思,是所有java程序的'孵化池'(玩过星际虫族的兄弟都晓得的).用ps 输出可以看到 >adb shell ...
- 设计模式-结合Android代码
开始学设计模式 1 单例模式 单例模式可以说是最容易理解的模式了,也是应用最广的模式之一,先看看定义吧. 定义:确保单例类只有一个实例,并且这个单例类提供一个函数接口让其他类获取到这个唯一的实例. 什 ...
- Android中的IPC机制
Android IPC简介 IPC是Inter-Process Communication的缩写,含义就是进程间通信或者跨进程通信,是指两个进程之间进行数据交换的过程.那么什么是进程,什么是线程,进程 ...
- 《android开发艺术探索》读书笔记(二)--IPC机制
接上篇<android开发艺术探索>读书笔记(一) No1: 在android中使用多进程只有一种方法,那就是给四大组件在AndroidMenifest中指定android:process ...
- Android开发艺术探索——第二章:IPC机制(上)
Android开发艺术探索--第二章:IPC机制(上) 本章主要讲解Android的IPC机制,首先介绍Android中的多进程概念以及多进程开发模式中常见的注意事项,接着介绍Android中的序列化 ...
- android binder机制详解
摘要 Binder是android中一个很重要且很复杂的概念,它在系统的整体运作中发挥着极其重要的作用,不过本文并不打算从深层次分析Binder机制,有两点原因:1是目前网上已经有2篇很好的文章了,2 ...
随机推荐
- curl tutorial with examples of usage
原文:http://www.yilmazhuseyin.com/blog/dev/curl-tutorial-examples-usage/ 阮一峰的这个教程也不错:http://www.ruanyi ...
- 【NLP】simhash判断文档相似度
http://blog.csdn.net/heiyeshuwu/article/details/44117473
- web front end stack web 前段技术概览
https://github.com/unruledboy/WebFrontEndStack
- 爬豆瓣影评,记下解决maximum recursion depth exceeded in cmp
#主要是爬取后给别人做自然语言分析,没其他意思. #coding=utf8 import requests,re from lxml import etree import sys reload(sy ...
- splash渲染网页
#coding=utf8 import requests,time,random import threadpool render_html = 'http://192.168.30.128:8050 ...
- [原]unity3d之http多线程异步资源下载
郑重声明:转载请注明出处 U_探索 本文诞生于乐元素面试过程,被面试官问到AssetBundle多线程异步下载时,愣了半天,同样也被深深的鄙视一回(做了3年多u3d 这个都没用过),所以发誓要实现出来 ...
- Dubbo调用链(version:2.5.3)
Consumer 调用 Provider的过程: (CONSUMER)Dubbo服务调用处 --> 调用RPC代理 --> InvokerInvocationHandler#invoke( ...
- Java虚拟机(一):JVM内存结构
所有的Java开发人员可能会遇到这样的困惑?我该为堆内存设置多大空间呢?OutOfMemoryError的异常到底涉及到运行时数据的哪块区域?该怎么解决呢?其实如果你经常解决服务器性能问题,那么这些问 ...
- 【代码审计】BootCMS v1.1.3 文件上传漏洞分析
0x00 环境准备 BootCMS官网:http://www.kilofox.net 网站源码版本:BootCMS v1.1.3 发布日期:2016年10月17日 程序源码下载:http://w ...
- 顶点纹理shader
Shader "Custom/VertDisplace" { Properties { _MainTex ("Base (RGB)", 2D) = " ...