android技术

本文详细介绍了如何在Android应用中优化BaseAdapter的性能,包括使用ViewHolder减少内存开销,隐藏手机软键盘,开启线程与服务的正确方式,以及代码混淆与签名打包的技术细节。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一.编译BaseAdapter 中采用HiewHolder类,节省内存资源
public View getView(int position, View convertView, ViewGroup parent) {
     ViewHolder holder;
     if (convertView == null) {
         convertView = mInflater.inflate(R.layout.listitem_route_hv, null);
         holder = new ViewHolder();
/* 得到各个控件的对象 */
         holder.people_icon = (TextView) convertView
                 .findViewById(R.id.people_icon);
         holder.route_num = (TextView) convertView
                 .findViewById(R.id.route_num);
         holder.site_name = (TextView) convertView.findViewById(R.id.site_name);
         convertView.setTag(holder); // 绑定ViewHolder对象

     } else {
         holder = (ViewHolder) convertView.getTag(); // 取出ViewHolder对象
     }

     return convertView;
 }
 private final class ViewHolder {
     public TextView people_icon;
     public TextView route_num;
     public TextView site_name;
 }

二.将手机软盘缩回隐藏。
InputMethodManager floppydisk = (InputMethodManager) v.getContext( ).getSystemService( Context.INPUT_METHOD_SERVICE );
floppydisk.hideSoftInputFromWindow(v.getApplicationWindowToken(), 0);

三.开一个线程
Thread thread=new Thread(new Runnable()
{
    @Override
    public void run()
    {
        takeActivity.startService(intent);
    }
});
thread.start();

当开完线程后,可以不用特意去销毁线程,当survice完成后程序自动销毁线程。除非线程循环才要销毁。

四.代码混淆
1.在build.grade中设置release
release {
    signingConfig signingConfigs.release
    minifyEnabled true
    //Zipalign优化
    zipAlignEnabled true
    // 移除无用的resource文件
  //  shrinkResources true
    proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            def outputFile = output.outputFile
            if (outputFile != null && outputFile.name.endsWith('.apk')) {
                def fileName = "${variant.productFlavors[0].name}_v${defaultConfig.versionName}_${releaseTime()}_release_signed.apk"
                output.outputFile = new File(outputFile.parent, fileName)
            }
        }
    }
}
2.在proguard-rules.pro设置哪些要混淆哪些不需要混淆。


五.签名打包
Build->Generate Signed APK
创建数字证书key,然后点击finish,选择release版本即可。
六.grade构建原理



                
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

kunzai6

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值