《移动项目实践》实验报告——Android数据存储

实验目的

1、熟悉Android五种主要存储方式的用法,包括共享参数SharedPreferences、数据库SQLite、SD卡文件、App的全局内存;
2、熟悉重要组件之一的应用Application的基本概念与常见用法,以及四大组件之一的内容提供器ContentProvider的基本概念与常见用法;

实验内容

“购物车”的设计与实现(参考效果图)

  1. 初始效果
    在这里插入图片描述

  2. 手机商场的商品列表
    在这里插入图片描述

  3. 商品详情页面
    在这里插入图片描述

  4. 添加商品后的购物车

    在这里插入图片描述

实验过程(实验的设计思路、关键源代码等)

源代码:https://gitee.com/shentuzhigang/mini-project/tree/master/android-shopping

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffffdd"
    android:orientation="vertical" >

    <include layout="@layout/activity_shopping_title" />

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="5dp" >
            
            <LinearLayout
                android:id="@+id/ll_content"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:visibility="gone" >

                <LinearLayout
                    android:id="@+id/ll_cart"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical" >
                </LinearLayout>
                
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal"
                    android:padding="10dp" >

                    <TextView
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:gravity="center|right"
                        android:text="总金额:"
                        android:textColor="@color/black"
                        android:textSize="17sp" />

                    <TextView
                        android:id="@+id/tv_total_price"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="2"
                        android:gravity="center|left"
                        android:textColor="@color/red"
                        android:textSize="25sp" />

                    <Button
                        android:id="@+id/btn_settle"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="结算"
                        android:textColor="@color/black"
                        android:textSize="20sp" />
                </LinearLayout>

            </LinearLayout>

            <LinearLayout
                android:id="@+id/ll_empty"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:visibility="gone" >

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="100dp"
                    android:layout_marginTop="100dp"
                    android:gravity="center"
                    android:text="哎呀,购物车空空如也,快去选购商品吧"
                    android:textColor="@color/black"
                    android:textSize="17sp" />

                <Button
                    android:id="@+id/btn_shopping_channel"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:text="逛逛手机商场"
                    android:textColor="@color/black"
                    android:textSize="17sp" />
            </LinearLayout>
        </FrameLayout>
    </ScrollView>

</LinearLayout>
package io.shentuzhigang.demo.shopping

import android.annotation.SuppressLint
import android.app.Activity
import android.app.AlertDialog
import android.content.Intent
import android.graphics.BitmapFactory
import android.graphics.Color
import android.os.Bundle
import android.os.Environment
import android.util.Log
import android.util.TypedValue
import android.view.*
import android.view.ContextMenu.ContextMenuInfo
import android.widget.ImageView
import android.widget.ImageView.ScaleType
import android.widget.LinearLayout
import android.widget.TextView
import android.widget.Toast
import io.shentuzhigang.demo.shopping.MainApplication
import io.shentuzhigang.demo.shopping.bean.CartInfo
import io.shentuzhigang.demo.shopping.bean.GoodsInfo
import io.shentuzhigang.demo.shopping.database.CartDBHelper
import io.shentuzhigang.demo.shopping.database.GoodsDBHelper
import io.shentuzhigang.demo.shopping.util.FileUtil
import io.shentuzhigang.demo.shopping.util.SharedUtil
import java.util.*

/**
 * Created by ouyangshen on 2017/10/1.
 */
@SuppressLint("SetTextI18n")
class ShoppingCartActivity : Activity(), View.OnClickListener {
    private lateinit var iv_menu: ImageView
    private lateinit var tv_count: TextView
    private lateinit var tv_total_price: TextView
    private lateinit var ll_content: LinearLayout
    private lateinit var ll_cart: LinearLayout
    private lateinit var ll_empty: LinearLayout
    private var mCount // 购物车中的商品数量
            = 0
    private var mGoodsHelper // 声明一个商品数据库的帮助器对象
            : GoodsDBHelper? = null
    private var mCartHelper // 声明一个购物车数据库的帮助器对象
            : CartDBHelper? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        requestWindowFeature(Window.FEATURE_NO_TITLE)
        setContentView(R.layout.activity_shopping_cart)
        iv_menu = findViewById(R.id.iv_menu)
        val tv_title = findViewById<TextView>(R.id.tv_title)
        tv_count = findViewById(R.id.tv_count)
        tv_total_price = findViewById(R.id.tv_total_price)
        ll_content = findViewById(R.id.ll_content)
        ll_cart = findViewById(R.id.ll_cart)
        ll_empty = findViewById(R.id.ll_empty)
        iv_menu.setOnClickListener(this)
        findViewById<View>(R.id.btn_shopping_channel).setOnClickListener(this)
        findViewById<View>(R.id.btn_settle).setOnClickListener(this)
        iv_menu.setVisibility(View.VISIBLE)
        tv_title.text = "购物车"
    }

    // 显示购物车图标中的商品数量
    private fun showCount(count: Int) {
        mCount = count
        tv_count!!.text = "" + mCount
        if (mCount == 0) {
            ll_content!!.visibility = View.GONE
            ll_cart!!.removeAllViews()
            ll_empty!!.visibility = View.VISIBLE
        } else {
            ll_content!!.visibility = View.VISIBLE
            ll_empty!!.visibility = View.GONE
        }
    }

    override fun onClick(v: View) {
        if (v.id == R.id.iv_menu) { // 点击了菜单图标
            openOptionsMenu()
        } else if (v.id == R.id.btn_shopping_channel) { // 点击了“商场”按钮
            // 跳转到手机商场页面
            val intent = Intent(this, ShoppingChannelActivity::class.java)
            startActivity(intent)
        } else if (v.id == R.id.btn_settle) { // 点击了“结算”按钮
            val builder = AlertDialog.Builder(this)
            builder.setTitle("结算商品")
            builder.setMessage("客官抱歉,支付功能尚未开通,请下次再来")
            builder.setPositiveButton("我知道了", null)
            builder.create().show()
        }
    }

    override fun onCreateOptionsMenu(menu: Menu): Boolean {
        // 从menu_cart.xml中构建菜单界面布局
        menuInflater.inflate(R.menu.menu_cart, menu)
        return true
    }

    override fun onOptionsItemSelected(item: MenuItem): Boolean {
        val id = item.itemId
        if (id == R.id.menu_shopping) { // 点击了菜单项“去商场购物”
            // 跳转到商场页面
            val intent = Intent(this, ShoppingChannelActivity::class.java)
            startActivity(intent)
        } else if (id == R.id.menu_clear) { // 点击了菜单项“清空购物车”
            // 清空购物车数据库
            mCartHelper!!.deleteAll()
            ll_cart!!.removeAllViews()
            // 把最新的商品数量写入共享参数
            SharedUtil.Companion.getIntance(this)!!.writeShared("count", "0")
            // 显示最新的商品数量
            showCount(0)
            mCartGoods.clear()
            mGoodsMap.clear()
            Toast.makeText(this, "购物车已清空", Toast.LENGTH_SHORT).show()
        } else if (id == R.id.menu_return) { // 点击了菜单项“返回”
            finish()
        }
        return true
    }

    // 声明一个根据视图编号查找商品信息的映射
    private val mCartGoods: HashMap<Int, CartInfo> = HashMap<Int, CartInfo>()

    // 声明一个触发上下文菜单的视图对象
    private var mContextView: View? = null
    override fun onCreateContextMenu(menu: ContextMenu, v: View, menuInfo: ContextMenuInfo) {
        // 保存该商品行的视图,以便删除商品时一块从列表移除该行
        mContextView = v
        // 从menu_goods.xml中构建菜单界面布局
        menuInflater.inflate(R.menu.menu_goods, menu)
    }

    override fun onContextItemSelected(item: MenuItem): Boolean {
        val info: CartInfo? = mCartGoods[mContextView!!.id]
        val id = item.itemId
        if (id == R.id.menu_detail) { // 点击了菜单项“查看商品详情”
            // 跳转到查看商品详情页面
            goDetail(info!!.goods_id)
        } else if (id == R.id.menu_delete) { // 点击了菜单项“从购物车删除”
            val goods_id: Long = info!!.goods_id
            // 从购物车删除商品的数据库操作
            mCartHelper!!.delete("goods_id=$goods_id")
            // 从购物车列表中删除该商品行
            ll_cart!!.removeView(mContextView)
            // 更新购物车中的商品数量
            var left_count: Int = mCount - info!!.count
            for (i in mCartArray!!.indices) {
                if (goods_id == mCartArray!![i].goods_id) {
                    left_count = mCount - mCartArray!![i].count
                    mCartArray!!.removeAt(i)
                    break
                }
            }
            // 把最新的商品数量写入共享参数
            SharedUtil.Companion.getIntance(this)!!.writeShared("count", "" + left_count)
            // 显示最新的商品数量
            showCount(left_count)
            Toast.makeText(this, "已从购物车删除" + mGoodsMap[goods_id]!!.name, Toast.LENGTH_SHORT).show()
            mGoodsMap.remove(goods_id)
            refreshTotalPrice()
        }
        return true
    }

    // 跳转到商品详情页面
    private fun goDetail(rowid: Long) {
        val intent = Intent(this, ShoppingDetailActivity::class.java)
        intent.putExtra("goods_id", rowid)
        startActivity(intent)
    }

    override fun onResume() {
        super.onResume()
        // 获取共享参数保存的购物车中的商品数量
        mCount = SharedUtil.Companion.getIntance(this)!!.readShared("count", "0")!!.toInt()
        showCount(mCount)
        // 获取商品数据库的帮助器对象
        mGoodsHelper = GoodsDBHelper.Companion.getInstance(this, 1)
        // 打开商品数据库的写连接
        mGoodsHelper!!.openWriteLink()
        // 获取购物车数据库的帮助器对象
        mCartHelper = CartDBHelper.Companion.getInstance(this, 1)
        // 打开购物车数据库的写连接
        mCartHelper!!.openWriteLink()
        // 模拟从网络下载商品图片
        downloadGoods()
        // 展示购物车中的商品列表
        showCart()
    }

    override fun onPause() {
        super.onPause()
        // 关闭商品数据库的数据库连接
        mGoodsHelper!!.closeLink()
        // 关闭购物车数据库的数据库连接
        mCartHelper!!.closeLink()
    }

    // 声明一个起始的视图编号
    private val mBeginViewId = 0x7F24FFF0

    // 声明一个购物车中的商品信息队列
    private var mCartArray: ArrayList<CartInfo>? = ArrayList<CartInfo>()

    // 声明一个根据商品编号查找商品信息的映射
    private val mGoodsMap: HashMap<Long, GoodsInfo?> = HashMap<Long, GoodsInfo?>()

    // 展示购物车中的商品列表
    private fun showCart() {
        // 查询购物车数据库中所有的商品记录
        mCartArray = mCartHelper!!.query("1=1")
        Log.d(TAG, "mCartArray.size()=" + mCartArray!!.size)
        if (mCartArray == null || mCartArray!!.size <= 0) {
            return
        }
        // 移除线性视图ll_cart下面的所有子视图
        ll_cart.removeAllViews()
        // 创建一个标题行的线性视图ll_row
        var ll_row = newLinearLayout(LinearLayout.HORIZONTAL, ViewGroup.LayoutParams.WRAP_CONTENT)
        ll_row.addView(newTextView(0, 2f, Gravity.CENTER, "图片", Color.BLACK, 15))
        ll_row.addView(newTextView(0, 3f, Gravity.CENTER, "名称", Color.BLACK, 15))
        ll_row.addView(newTextView(0, 1f, Gravity.CENTER, "数量", Color.BLACK, 15))
        ll_row.addView(newTextView(0, 1f, Gravity.CENTER, "单价", Color.BLACK, 15))
        ll_row.addView(newTextView(0, 1f, Gravity.CENTER, "总价", Color.BLACK, 15))
        // 把标题行添加到购物车列表
        ll_cart.addView(ll_row)
        for (i in mCartArray!!.indices) {
            val info: CartInfo = mCartArray!![i]
            // 根据商品编号查询商品数据库中的商品记录
            val goods: GoodsInfo? = mGoodsHelper!!.queryById(info.goods_id)
            Log.d(TAG, "name=" + goods!!.name + ",price=" + goods.price + ",desc=" + goods.desc)
            mGoodsMap[info.goods_id] = goods
            // 创建该商品行的水平线性视图,从左到右依次为商品小图、商品名称与描述、商品数量、商品单价、商品总价。
            ll_row = newLinearLayout(LinearLayout.HORIZONTAL, ViewGroup.LayoutParams.WRAP_CONTENT)
            // 设置该线性视图的编号
            ll_row.id = mBeginViewId + i
            // 添加商品小图
            val iv_thumb = ImageView(this)
            val iv_params = LinearLayout.LayoutParams(
                0, ViewGroup.LayoutParams.WRAP_CONTENT, 2F
            )
            iv_thumb.layoutParams = iv_params
            iv_thumb.scaleType = ScaleType.FIT_CENTER
            iv_thumb.setImageBitmap(MainApplication.instance?.mIconMap?.get(info.goods_id))
            ll_row.addView(iv_thumb)
            // 添加商品名称与描述
            val ll_name = LinearLayout(this)
            val params = LinearLayout.LayoutParams(
                0, ViewGroup.LayoutParams.MATCH_PARENT, 3F
            )
            ll_name.layoutParams = params
            ll_name.orientation = LinearLayout.VERTICAL
            ll_name.addView(newTextView(-3, 1f, Gravity.LEFT, goods.name, Color.BLACK, 17))
            ll_name.addView(newTextView(-3, 1f, Gravity.LEFT, goods.desc, Color.GRAY, 12))
            ll_row.addView(ll_name)
            // 添加商品数量、单价和总价
            ll_row.addView(newTextView(1, 1f, Gravity.CENTER, "" + info.count, Color.BLACK, 17))
            ll_row.addView(
                newTextView(
                    1,
                    1f,
                    Gravity.RIGHT,
                    "" + goods.price.toInt(),
                    Color.BLACK,
                    15
                )
            )
            ll_row.addView(
                newTextView(
                    1,
                    1f,
                    Gravity.RIGHT,
                    "" + (info.count * goods.price).toInt(),
                    Color.RED,
                    17
                )
            )
            // 给商品行添加点击事件
            ll_row.setOnClickListener { goDetail(info.goods_id) }
            // 给商品行注册上下文菜单,为防止重复注册,这里先注销再注册
            unregisterForContextMenu(ll_row)
            registerForContextMenu(ll_row)
            mCartGoods[ll_row.id] = info
            // 往购物车列表添加该商品行
            ll_cart.addView(ll_row)
        }
        // 重新计算购物车中的商品总金额
        refreshTotalPrice()
    }

    // 重新计算购物车中的商品总金额
    private fun refreshTotalPrice() {
        var total_price = 0
        for (info in mCartArray!!) {
            val goods: GoodsInfo? = mGoodsMap[info.goods_id]
            total_price += (goods!!.price * info.count).toInt()
        }
        tv_total_price.text = "" + total_price
    }

    // 创建一个线性视图的框架
    private fun newLinearLayout(orientation: Int, height: Int): LinearLayout {
        val ll_new = LinearLayout(this)
        val params = LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, height
        )
        ll_new.layoutParams = params
        ll_new.orientation = orientation
        ll_new.setBackgroundColor(Color.WHITE)
        return ll_new
    }

    // 创建一个文本视图的模板
    private fun newTextView(
        height: Int,
        weight: Float,
        gravity: Int,
        text: String,
        textColor: Int,
        textSize: Int
    ): TextView {
        val tv_new = TextView(this)
        if (height == -3) {  // 垂直排列
            val params = LinearLayout.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT, 0, weight
            )
            tv_new.layoutParams = params
        } else {  // 水平排列
            val params = LinearLayout.LayoutParams(
                0,
                if (height == 0) ViewGroup.LayoutParams.WRAP_CONTENT else ViewGroup.LayoutParams.MATCH_PARENT,
                weight
            )
            tv_new.layoutParams = params
        }
        tv_new.text = text
        tv_new.setTextColor(textColor)
        tv_new.setTextSize(TypedValue.COMPLEX_UNIT_SP, textSize.toFloat())
        tv_new.gravity = Gravity.CENTER or gravity
        return tv_new
    }

    private var mFirst: String? = "true" // 是否首次打开

    // 模拟网络数据,初始化数据库中的商品信息
    private fun downloadGoods() {
        // 获取共享参数保存的是否首次打开参数
        mFirst = SharedUtil.Companion.getIntance(this)!!.readShared("first", "true")
        // 获取当前App的私有存储路径
        val path: String = MainApplication.instance?.getExternalFilesDir(
            Environment.DIRECTORY_DOWNLOADS
        ).toString().toString() + "/"
        if (mFirst == "true") { // 如果是首次打开
            val goodsList: ArrayList<GoodsInfo> = GoodsInfo.defaultList
            for (i in goodsList.indices) {
                val info: GoodsInfo = goodsList[i]
                // 往商品数据库插入一条该商品的记录
                val rowid: Long = mGoodsHelper!!.insert(info)
                info.rowid = rowid
                // 往全局内存写入商品小图
                val thumb = BitmapFactory.decodeResource(resources, info.thumb)
                MainApplication.instance?.mIconMap?.put(rowid, thumb)
                val thumb_path = path + rowid + "_s.jpg"
                FileUtil.saveImage(thumb_path, thumb)
                info.thumb_path = thumb_path
                // 往SD卡保存商品大图
                val pic = BitmapFactory.decodeResource(resources, info.pic)
                val pic_path = "$path$rowid.jpg"
                FileUtil.saveImage(pic_path, pic)
                pic.recycle()
                info.pic_path = pic_path
                // 更新商品数据库中该商品记录的图片路径
                mGoodsHelper!!.update(info)
            }
        } else { // 不是首次打开
            // 查询商品数据库中所有商品记录
            val goodsArray: ArrayList<GoodsInfo> = mGoodsHelper!!.query("1=1")
            for (i in goodsArray.indices) {
                val info: GoodsInfo = goodsArray[i]
                // 从指定路径读取图片文件的位图数据
                val thumb = BitmapFactory.decodeFile(info.thumb_path)
                // 把该位图对象保存到应用实例的全局变量中
                MainApplication.instance?.mIconMap?.put(info.rowid, thumb)
            }
        }
        // 把是否首次打开写入共享参数
        SharedUtil.Companion.getIntance(this)!!.writeShared("first", "false")
    }

    companion object {
        private const val TAG = "ShoppingCartActivity"
    }
}

实验结果(实验最终作品截图说明)

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

实验心得

1、熟悉Android五种主要存储方式的用法,包括共享参数SharedPreferences、数据库SQLite、SD卡文件、App的全局内存;
2、熟悉重要组件之一的应用Application的基本概念与常见用法,以及四大组件之一的内容提供器ContentProvider的基本概念与常见用法;

参考文章

  • 0
    点赞
  • 27
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
实验报告封面 课程名称: Android平台开发与应用 课程代码: SM3004 任课老师: 梁郁君 实验指导老师: 梁郁君 实验报告名称:实验10 Android数据存储与IO 学生姓名: 学号: 教学班: 递交日期: 签收人: 我申明,本报告内的实验已按要求完成,报告完全是由我个人完成,并没有抄袭行 为。我已经保留了这份实验报告的副本。 申明人(签名): 实验报告评语与评分: 评阅老师签名: 一、实验名称:Android数据存储与IO 二、实验日期:2014/11/13 三、实验目的: 1、掌握SharedPreferences的存储数据的格式及位置,能够读写其他应用程序的Shared Preferences。 2、File存储数据 3、掌握SQLite存储数据方法。 4、会使用SQLiteOpenHelper辅助类,进行操作数据库。 四、实验用的仪器和材料: PC+Eclipse+ADT 五、实验的步骤和方法: 1、读写其他应用程序SharedPreferences。 读写其他应用程序的SharedPreferences,步骤如下: 创建应用App1 和应用App2,App2尝试读取App1的SharedPreferences内容 在App2 需要创建App1对应的Context。 调用App1的Context的getSharedPreferences(String name,int mode) 即可获取相应的SharedPreferences对象。 如果需要向App1的SharedPreferences数据写入数据,调用SharedPreferences的e dit()方法获取相应的Editor即可。 根据上述说明和下面截图,以及代码注释,完成相关代码片段填空,并思考问题: SharedPreferences何时会丢失? 图1 App1运行的界面 图2 App2 运行结果 App1:记录应用程序的使用次数,/com.Test/UseCount.java程序如下,补充程序中所缺 代码: "import android.app.Activity; " "import android.content.SharedPreferences; " "import android.content.SharedPreferences.Editor; " "import android.os.Bundle; " "import android.widget.Toast; " "public class UseCount extends Activity{ " "SharedPreferences preferences; " "@Override " "public void onCreate(Bundle savedInstanceState){ " "super.onCreate(savedInstanceState); " "setContentView(R.layout.main); " "preferences = getSharedPreferences("count", MODE_WORLD_READABLE); " "//读取SharedPreferences里的count数据 " "int count = ("count" , 0); " "//显示程序以前使用的次数 " "Toast.makeText(this , "程序以前被使用了" + count + "次。", " "10000).show(); " "Editor editor = ; " "//存入数据 " "editor.putInt("count" , ++count); " "//提交修改 " "editor. ; " "} " "} " App2:ReadOtherPreferences.java代码如下,补充程序所缺代码: "import android.app.Activity; " "import android.content.Context; " "import android.content.SharedPreferences; " "import " "android.content.pm.PackageManager.NameNotFoundException; " "import android.os.Bundle; " "import android.widget.TextView; " "public class ReadOtherPreferences extends Activity{ " "Context useCount; " "@Override " "public void onCreate(Bundle sav
Android Studio 是一款由谷歌开发的集成开发环境(IDE),用于开发 Android 应用程序。在 Android Studio 中,界面跳转和数据传输是移动应用开发中两个重要的方面。 界面跳转: 1. 使用 Intent:在 Android 中,Intent 是一个非常重要的类,用于启动一个 Activity。通过使用 Intent,你可以从一个 Activity 跳转到另一个 Activity。Intent 包含一个动作(action)和一个或多个数据(data),这决定了 Activity 的类型和需要的数据。 2. 使用导航架构:Android 支持多种导航架构,如 Tab 组件、Drawer、ViewPager 等,可以让你轻松地实现页面间的跳转。例如,你可以创建一个 Drawer 组件,其中包含多个选项,用户可以通过点击这些选项在不同的页面之间进行跳转。 3. 使用 Fragment:Fragment 是 Android 中的一个重要组件,用于构建应用程序的界面。Fragment 可以与多个视图组件(如 ViewPager 或 ListView)关联,允许你以更灵活的方式创建和管理界面。你可以将 Fragment 添加到 Activity 中,并在需要时进行跳转。 数据传输: 1. 使用 Intent extras:Intent 提供了一个机制,可以将数据从一个 Activity 或 Service 传递到另一个。你可以使用 Intent 的 extras 字段来传递数据,例如使用 Bundle 类来存储键值对。 2. 使用 SharedPreferences:SharedPreferences 是 Android 提供的一种轻量级存储机制,用于保存应用程序的短期配置和数据。SharedPreferences 可以用于保存简单的数据类型,如字符串、布尔值或整数值。 3. 使用网络通信:如果你的应用程序需要与服务器进行数据交互,你可能需要使用网络通信技术。Android 支持多种网络通信方式,如 HTTP、HTTPS 和蓝牙通信等。你可以使用 Java 的 HttpURLConnection 类或第三方库(如 OkHttp)来实现网络通信。 4. 使用数据库:如果你的应用程序需要存储大量数据,你可能需要使用数据库。Android 支持 SQLite 数据库,它是一种轻量级的关系型数据库,可以用于存储和检索应用程序的数据。 总的来说,Android Studio 提供了一些强大的工具和功能,可以帮助你实现移动应用开发中的界面跳转和数据传输。你可以根据具体的需求和场景选择合适的技术和方法来实现这些功能。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

Starzkg

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

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

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

打赏作者

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

抵扣说明:

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

余额充值