首页 > 解决方案 > 使用日期来管理订阅。安卓。火力基地

问题描述

我的问题是这个活动。我想获取时间,将其与数据库上的时间进行比较,然后如果订阅尚未过期,则显示一个按钮,如果它已隐藏它。另外,我想在顶部显示用户的信用,以及图像和他的名字。我尝试了很多东西,但由于某种原因它一直在崩溃。

public void getthedate(){

   calendar = Calendar.getInstance();
    final SimpleDateFormat mdformat = new SimpleDateFormat("yyyy / MM / dd ");
   // strDate = "Current Date : " + mdformat.format(calendar.getTime());

 //  futurecal = Calendar.getInstance();
  //  futurecal.add(Calendar.DATE, 30);
  //  futuredate = mdformat.format(futurecal.getTime());

    DatabaseReference subtime = mDatabase.child("users").child(univ).child(uid);
    subtime.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
          subtimedate = dataSnapshot.child("subdate").getValue().toString();
            String username = dataSnapshot.child("Full name").getValue().toString();
            String coinstring = dataSnapshot.child("coins").getValue().toString();
            coinview.setText(coinstring);
            String imglink = dataSnapshot.child("imageuri").getValue().toString();
            Glide.with(c).load(imglink).into(userthing);
            hellostring.setText("Hey" + username + "!");
            Date subdatecal = null;
            try {
                subdatecal = mdformat.parse(subtimedate);
            } catch (ParseException e) {
                e.printStackTrace();
            }
            Calendar newestcal = Calendar.getInstance();
          newestcal.setTime(subdatecal);

            if (newestcal.after(mdformat.format(calendar.getTime()))){
                substat.setText("Active");
                substat.setBackgroundColor(Color.GREEN);
               //do something if subscription hasnt expired
            }else{
                gotonotes.setVisibility(View.GONE);
                substat.setText("Expired");
                substat.setBackgroundColor(Color.RED);
            }

        }

        @Override
        public void onCancelled(@NonNull DatabaseError databaseError) {

        }
    });


    /*
    DatabaseReference subtime = mDatabase.child("users").child(univ).child(uid).child("subdate");
    subtime.setValue(futuredate);

    set new subscription

    */
/* if (calendar.after(futurecal)){
     use this to check if date has passed
 }*/
}

在 oncreate 我已经设置了一切。

substat = (TextView) findViewById(R.id.substat);
hellostring = (TextView) findViewById(R.id.hellostring);
coinview = (TextView) findViewById(R.id.coinview);
userthing = (ImageView) findViewById(R.id.userimagething);
        mDatabase = FirebaseDatabase.getInstance().getReference();

        friendbtn = (Button) findViewById(R.id.friendsbtn);

        uid = FirebaseAuth.getInstance().getCurrentUser().getUid();

感谢您的任何建议!

这是活动崩溃时我在 android studio 上的手机上的 logcat

10-22 19:00:46.363 20227-20227/? I/art: Late-enabling -Xcheck:jni
10-22 19:00:46.473 20227-20227/com.studybuddy.mixal.android W/System: ClassLoader referenced unknown path: /data/app/com.studybuddy.mixal.android-2/lib/arm64
10-22 19:00:46.592 20227-20227/com.studybuddy.mixal.android I/FirebaseInitProvider: FirebaseApp initialization successful
10-22 19:00:46.635 20227-20227/com.studybuddy.mixal.android W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
10-22 19:00:46.639 20227-20261/com.studybuddy.mixal.android I/FA: App measurement is starting up, version: 12780
    To enable debug logging run: adb shell setprop log.tag.FA VERBOSE
    To enable faster debug mode event logging run:
      adb shell setprop debug.firebase.analytics.app com.studybuddy.mixal.android
10-22 19:00:46.703 20227-20261/com.studybuddy.mixal.android I/FA: Tag Manager is not found and thus will not be used
10-22 19:00:46.705 20227-20227/com.studybuddy.mixal.android I/HwSecImmHelper: mSecurityInputMethodService is null
10-22 19:00:46.718 20227-20227/com.studybuddy.mixal.android E/HAL: load: id=gralloc != hmi->id=gralloc
10-22 19:00:46.899 20227-20284/com.studybuddy.mixal.android I/DynamiteModule: Considering local module com.google.android.gms.firebase_database:4 and remote module com.google.android.gms.firebase_database:6
    Selected remote version of com.google.android.gms.firebase_database, version >= 6
10-22 19:00:46.949 20227-20284/com.studybuddy.mixal.android W/System: ClassLoader referenced unknown path: /data/data/com.google.android.gms/app_chimera/m/00000086/n/arm64-v8a
10-22 19:00:46.960 20227-20272/com.studybuddy.mixal.android E/HAL: load: id=gralloc != hmi->id=gralloc
10-22 19:00:46.961 20227-20272/com.studybuddy.mixal.android I/OpenGLRenderer: Initialized EGL, version 1.4
10-22 19:00:46.971 20227-20272/com.studybuddy.mixal.android W/OpenGLRenderer: load: so=/system/lib64/libhwuibp.so
    dlopen failed: library "/system/lib64/libhwuibp.so" not found
    Initialize Binary Program Cache: Load Failed
10-22 19:00:46.971 20227-20272/com.studybuddy.mixal.android E/HAL: load: id=gralloc != hmi->id=gralloc
10-22 19:00:47.058 20227-20299/com.studybuddy.mixal.android I/System: core_booster, getBoosterConfig = false
10-22 19:00:48.781 20227-20227/com.studybuddy.mixal.android I/Process: Sending signal. PID: 20227 SIG: 9

标签: javaandroidfirebaseandroid-studiodate

解决方案


推荐阅读