Younix's Studio.

SOP_Intent传输对象的方法
正常的 Intent 传值的方法1234Intent intent = new Intent(FirstActivity.this, SecondActivity.class);intent.putExtra("string_data","hello");intent.putExtra("int_data",100);startActivity(intent); 在 SecondActivity 众通过 getIntent 获取值12getIntent().getStringExtra("string_data&quo...
数据持久化_数据库_LitePal 和 SQLite
LitePal 基本概念LitePal 是开源的 Android 数据库框架, 采用了 对象关系映射 ORM 模式 .封装了常用数据库功能 ORM(对象关系映射) 指的是 面向对象语言 和 关系型数据库 之间建立一种映射关系. 使用方法配置123dependencies { compile 'org.litepal.android:core:2.0.0'} 1android:name="org.litepal.LitePalApplication" litepal.xml 1Connector.ge...
SOP_全局获取Context方法
利用 Application 类.当应用程序启动时 , 系统会自动对 Applicaiton 类进行初始化.我们可以定制自己的一个 Application 类, 以便于管理程序内的 全局状态信息. 自定义 WholeApplication 类1234567891011public class WholeApplication extends Application { private static Context context; public void onCreate() { context = getApplicationContext()...
SOP_WebView_XML和JSON
JSON两种解析方法 JSONObject123456789101112131415161718private void parseJSONWithJSONObject(String jsonData) { try { // 定义 JASON 数组 , 将服务器返回的数据传入到了 JSONObject 对象中 JSONArray jsonArray = new JSONArray(jsonData); for(int i = 0; i < jsonArray.length(); i+...
SOP_动态权限
在程序运行的过程中由用户去授权执行某些可能是危险的的操作. 实现步骤 检查权限ContextCompat.checkSelfPermission参数 1 Context参数 2 具体的权限名字 12345ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.CALL_PHONE)判断有无权限:ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.CALL_PHONE) != PackageManage...
SOP_多线程编程
通过实现 Runnable 接口的实例来创建线程123456789101112131415161718192021222324252627282930313233343536373839404142class RunnableDemo implements Runnable { private Thread t; private String threadName; RunnableDemo( String name) { threadName = name; System.out.println("Creating &...
SOP_控件_Fragment
Fragment 实例1234567891011121314151617181920212223protected void onCreate(Bundle savedInstanceState) { ... // 1. 创建待添加 fragment 实例 replaceFragment(fragment1); ...}private void replaceFragment(Fragment fragment) { // 2. 获取 FragmentManager FragmentManager fragmentMana...
SOP_控件_AlertDialog
12345678910111213AlertDialog.Builder builder = new AlertDialog.Builder(context);builder.setTitle("Warning");builder.setMessage("You are forced to be offline. Please try to login again.");builder.setCancelable(false); // 设置为不可取消builder.setPositiveButton("OK", new DialogInterface.OnClickListener() ...
数据持久化_文件存储
写123456789101112131415161718192021222324/** * 文件名 为 data * @param inputText */private void save(String inputText) { FileOutputStream out = null; BufferedWriter writer = null; try { out = openFileOutput("data", Context.MODE_PRIVATE); writer = new BufferedWriter(new...
数据持久化_SharedPreferences
简介通过键值对的方式进行存储. 保存为 xml 文件value - key 存储 获取 SharedPreferences 对象 SharedPreferences.Editor editor = getSharedPreferences(“data”, MODE_PRIVATE).edit(); editor.putString(“name”, “Tom”); editor.apply();123456// 通过 getSharedPreferences() 方法指定 SharedPreferences 文件名为 dataSharedPreferences.Editor editor ...