在Android项目中,遇到过的坑
来源:互联网 发布:信鸽推送demo php 编辑:程序博客网 时间:2024/04/27 15:20
更新时间 2016-04-05
0,在 Application 中调用 Activity 中 a() 方法,而 a() 方法中用到了 Context 对象,此时崩溃。
解决办法:将 Context 形参赋值为 Application 的 Context 对象。
1,注意隐式Intent的运行检查
隐式Intent找不到合适的调用组件的情况,系统会抛出 ActivityNotFoundException的异常,解决方案:
Intent intent = new Intent(Intent.ACTION_XXX);ComponentName name = intent.resolveActivity(context.getPackageManager());if (name != null) { String className = name.getClassName();}
2,使用 NotificationCompat 处理消息通知
// Add your color 5.0int color = context.getResources().getColor(R.color.white);// a large iconBitmap profileIcon = XXX;builder.setLargeIcon(profileIcon);builder.setStyle(new NotificationCompat.BigTextStyle(test));PendingIntent pendingIntent = XXX;builder.addAction(new NotificationCompat().Action(R.mipmap.ic_launcher, "Test", intent));// 穿戴设备NotificationCompat.WearableExtender wearableExtender = new NotificationCompat.WearableExtender();// do the magicRemoteInput remoteInput = new RemoteInput.Builder("key").setLabel("replay").build();wearableExtender.addAction(new NotificationCompat.Action.Builder(R.mipmap.ic_launcher, "replay", replayIntent).addRemoteInput(remoteInput).build());builder.extend(wearableExtender);
3,Android 6.0 运行时权限
if (context.checkSelfPermission(Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED) { // already available} else { }更改后,会调用
@Overridepublic void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { if (requestCode == REQUEST_CAMERA) { if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { // } else { // } } else { super.onRequestPermissionsResult(requestCode, permissions, grantResults); }}
4,使用 MediaSessionCompat
<action android name="android.intent.action.MEDIA_BUTTON"/>
5,使用Toolbar代替Actionbar
需要继承主题Theme.AppCompat.NoActionBar
<android.support.v7.widget.Toolbar/>
setSupportActionBar(toolbar);
6,使用AppBarLayout
7,使用searchView
8,DrawerLayout, NavigationView
v4包
9,Tabs and ViewPager
0 0
- 在Android项目中,遇到过的坑
- 项目开发中遇到过的问题
- 在android项目中遇到的小问题
- 项目中曾经遇到过的问题整理
- 开发Android遇到过的坑
- iOS开发中遇到过的坑
- iOS开发中遇到过的坑
- iOS开发中遇到过的坑
- iOS开发中遇到过的坑
- iOS开发中遇到过的坑
- iOS开发中遇到过的坑
- iOS开发中遇到过的坑
- 你在开发中遇到过哪些坑?【不断更新中】
- Android打arr包并在项目中引用以及遇到的坑
- 在DELPHI中你遇到过这样的问题吗?
- 在项目中遇到的一些关于vue的坑
- 基于cef ceflient做二次开发在开发环境部署中遇到过的坑
- 纪念2017/2/16在项目中遇到的坑
- 利用python实现电影推荐
- Java中的static关键字解析
- POSIX 线程详解
- 抽象类、接口作为方法形参、返回值
- Kafka到Storm
- 在Android项目中,遇到过的坑
- HashMap排序
- [kipmi0]进程导致系统负载高
- 详解QuickCocos2dX状态机模式设计
- linux负载均衡
- Maven学习总结(17)——深入理解maven灵活的构建
- 虚拟机Linux c++调用Python脚本的实现
- 如何停止Monkey测试
- HTML5 - 用Modernizr检测浏览器对表单和表单验证的支持情况