Adnroid手机安全卫士

在做手机安全卫士的时候出现了很多问题,记录下来,方便自己学习。



1.使用SettingItemView继承RelativeLayout的时候。刚开始只继承了父类的一个方法,如下:

<span style="font-size:24px;">public class SettingItemView extends RelativeLayout {

    private TextView tvTitle;
    private TextView tvDesc;
    private CheckBox cbStatus;

 

    public SettingItemView(Context context) {
        super(context);
        initView();
    }

    //初始化布局
    private void initView(){
        //将自定义布局设置给SettingItemView
        View.inflate(getContext(), R.layout.view_setting_item,this);
        tvTitle= (TextView) findViewById(R.id.tv_title);
        tvDesc= (TextView) findViewById(R.id.tv_desc);
        cbStatus= (CheckBox) findViewById(R.id.cb_status);
    }


    public  void setTitle(String title){
        tvTitle.setText(title);
    }

    public void setTvDesc(String desc){
        tvDesc.setText(desc);
    }

    //判断勾选状态
    public boolean isChecked(){
        return cbStatus.isChecked();
    }

    //设置勾选状态
    public void setChecked(boolean check){
        cbStatus.setChecked(check);
    }

}
</span>
出现了运行程序闪退的状态,报错java.lang.ClassNotFoundException


修改如下:

public class SettingItemView extends RelativeLayout {

    private TextView tvTitle;
    private TextView tvDesc;
    private CheckBox cbStatus;

    public SettingItemView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView();
    }

    public SettingItemView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView();
    }

    public SettingItemView(Context context) {
        super(context);
        initView();
    }

    //初始化布局
    private void initView(){
        //将自定义布局设置给SettingItemView
        View.inflate(getContext(), R.layout.view_setting_item,this);
        tvTitle= (TextView) findViewById(R.id.tv_title);
        tvDesc= (TextView) findViewById(R.id.tv_desc);
        cbStatus= (CheckBox) findViewById(R.id.cb_status);
    }


    public  void setTitle(String title){
        tvTitle.setText(title);
    }

    public void setTvDesc(String desc){
        tvDesc.setText(desc);
    }

    //判断勾选状态
    public boolean isChecked(){
        return cbStatus.isChecked();
    }

    //设置勾选状态
    public void setChecked(boolean check){
        cbStatus.setChecked(check);
    }

}
程序正常运行。



2.在跳转手机防盗页面的时候出现了程序闪退,logcat不报错了情况。

<span style="font-size:24px;">  startActivity(new Intent(HomeActivity.this,LostFindActivity.class));</span>


原因:没有在AndroidManifest.xml中注册LostFindActivity.




3.在使用selector的时候,在drawable里的两张图片出现找不到资源的现象



去掉了两张图片中.9的后缀就行了




4.在读取sim卡信息的时候出现不能打印sim卡信息,错误如下:

现在都还不知道是怎么回事? 

今天重新跑了一下,发现可以打印了,可能是ide建项目的问题(猜测)



5.Android收不到开机广播问题

之前代码

 <receiver android:name="receiver.BootCompleteReceiver">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
            </intent-filter>
           
        </receiver>


之后代码

 <receiver android:name="receiver.BootCompleteReceiver">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
            </intent-filter>
            <intent-filter  >
                <action android:name="android.intent.action.MEDIA_MOUNTED" />
                <action android:name="android.intent.action.MEDIA_EJECT" />

                <data android:scheme="file" />
            </intent-filter>
        </receiver>



处理应用安装在sd后监听不到开机广播的问题,需要同时监听开机广播和sd卡挂载的广播,此外还要看一下是否添加了权限RECEIVE_BOOT_COMPLETED



6.关于assets文件夹的问题

有时候需要放置一些文件而且不被proguard压缩,或者放置数据库文件,可以放到assets目录中,

熟悉了eclipse的ide,在as中创建的项目并不会自动新建assets目录。应该要将文件放到/src/main/assets

否则会出现空指针异常:

java.lang.NullPointerException: Attempt to invoke virtual method 'void java.io.InputStream.close()' on a null object reference


7.关于数据库sqlite不支持varchar的问题

在建表的时候遇到这样的问题:


由于在建表时column的packagename 使用了varchar(20)类型 ,导致错误(?),应该使用text类型,

重新测试了一下,发现可能是建表的时候出现了问题,卸载app之后,再重装发现是可以支持varchar的



8.关于ActivityManager方法不能使用的问题


可能是as导包的问题,需要自己手动导包import android.app.ActivityManager; 

才能使用


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值