赞
踩
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:focusable="true"
- android:focusableInTouchMode="true"
- android:orientation="vertical"
- android:padding="10dp" >
-
- <TextView
- android:id="@+id/tv_app"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:textColor="@color/black"
- android:textSize="17sp" />
-
- </LinearLayout>
- package com.example.forth;
- import android.os.Bundle;
-
- import androidx.appcompat.app.AppCompatActivity;
-
-
- import android.widget.TextView;
- import android.widget.Toast;
-
- import java.util.Map;
-
-
- public class MainActivity extends AppCompatActivity {
- private TextView tv_app;
-
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_app_read);
- tv_app = findViewById(R.id.tv_app);
- readAppMemory();
- }
-
- // 读取全局内存中保存的变量信息
- private void readAppMemory() {
- String desc = "全局内存中保存的信息如下:";
- // 获取当前应用的Application实例
- MainApplication app = MainApplication.getInstance();
- // 获取Application实例中保存的映射全局变量
- Map<String, String> mapParam = app.mInfoMap;
- // 遍历映射全局变量内部的键值对信息
- for (Map.Entry<String, String> item_map : mapParam.entrySet()) {
- desc = String.format("%s\n %s的取值为%s",
- desc, item_map.getKey(), item_map.getValue());
- }
- if (mapParam.size() <= 0) {
- desc = "全局内存中保存的信息为空";
- }
- tv_app.setText(desc);
- }
-
- private void showToast(String desc) {
- Toast.makeText(this, desc, Toast.LENGTH_SHORT).show();
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。