基本信息
源码名称:安卓大作业,基本的听歌功能,备忘录功能
源码大小:20.13M
文件格式:.zip
开发语言:Java
更新时间:2022-01-07
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
安卓大作业,基本的听歌功能,备忘录功能
package com.example.activity;
import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; public class BootReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Intent i = new Intent(context, ThirdActivity.class); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // 指定Activity运行在任务栈中 context.startActivity(i); } } ackage com.example.activity; import java.io.File; import java.util.ArrayList; import java.util.Random; import android.app.Activity; import android.content.ContentResolver; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.net.Uri; import android.os.Bundle; import android.view.View; import android.widget.Toast; public class EighthActivity extends Activity { private StudentDBOpenHelper helper; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_eighth); helper = new StudentDBOpenHelper(this); // readDB(); readDBFromProvider(); } private void readDBFromProvider() { // TODO Auto-generated method stub ContentResolver contentResolver = getContentResolver(); Uri uri = Uri.parse("content://com.example.studentdb/query"); Cursor cursor = contentResolver.query(uri, null, null, null, null); while (cursor.moveToNext()) { int id = cursor.getInt(0); String name = cursor.getString(1); double score = cursor.getDouble(2); System.out .println("id=" id ",name=" name ",score=" score); } cursor.close(); } private void readDB() { // TODO Auto-generated method stub File file = new File( "/data/data/com.example.activity/databases/info.db"); System.out.println("文件是否存在:" file.exists()); SQLiteDatabase db = SQLiteDatabase.openDatabase( "/data/data/com.example.activity/databases/info.db", null, SQLiteDatabase.OPEN_READWRITE); Cursor cursor = db.query("student", null, null, null, null, null, null); while (cursor.moveToNext()) { int id = cursor.getInt(0); String name = cursor.getString(1); double score = cursor.getDouble(2); System.out .println("id=" id ",name=" name ",score=" score); } } public void update(View view) { SQLiteDatabase db = helper.getWritableDatabase(); db.execSQL("update student set score=? where name=?", new Object[] { "100", "张三54" }); db.close(); Toast.makeText(this, "更新成功!", 1).show(); } public void delete(View view) { SQLiteDatabase db = helper.getWritableDatabase(); db.execSQL("delete from student where name=?", new Object[] { "张三16" }); Toast.makeText(this, "删除成功!", 1).show(); db.close(); } public void add(View view) { SQLiteDatabase db = helper.getWritableDatabase(); Random random = new Random(); db.execSQL("insert into student(name,score) values(?,?)", new Object[] { "张三" random.nextInt(100), "98" random.nextInt(50) }); Toast.makeText(this, "添加成功!", 1).show(); db.close(); } public void findAll(View view) { SQLiteDatabase db = helper.getReadableDatabase(); Cursor cursor = db.rawQuery("select * from student", null); ArrayList<Student> list = new ArrayList<Student>(); while (cursor.moveToNext()) { Student student = new Student(); student.setId(cursor.getInt(0)); student.setName(cursor.getString(1)); student.setScore(cursor.getDouble(2)); list.add(student); } for (Student student : list) { System.out.println(student.toString()); } cursor.close(); db.close(); System.out.println("------"); } }