我有这个接收推送通知的应用程序,
首先在我的Application类中启用了像这样的磁盘持久性:
FirebaseDatabase.getInstance().setPersistenceEnabled(true);
然后我收到推送通知并点击它打开应用程序,这是调用的方法:
private void startIntent(final String msgID) {
mRefMessages = fbdb.getReference(AppConstants.TableMessages.Table_name);
mRefMessages.keepSynced(true);
mQueryMessg = mRefMessages.child(msgID).orderByValue() ;
Log.d(TAG ,"ref=>\n" + mQueryMessg.getRef().toString() ) ;
mQueryMessg.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
Log.d(TAG, "data snap Shot = " + dataSnapshot.getValue());
if (dataSnapshot.hasChild(AppConstants.Key_Type))
{
Toast.makeText(ActivityMessages.this, "have child type == true" , Toast.LENGTH_SHORT).show();
//open message view
//some code . . .
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
Log.d(TAG, "data base eror " + databaseError.toString());
}
});
}
如果我返回并禁用磁盘持久性我没有这种行为,并找到数据快照值!
为什么会这样?我缺少什么?
build.gradle片段
dependencies {
classpath 'com.android.tools.build:gradle:2.3.2'
classpath 'com.google.gms:google-services:3.1.0'
classpath 'com.google.firebase:firebase-plugins:1.1.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
我正在使用11.0.2版本的firebase sdk
android {
compileSdkVersion 26
buildToolsVersion "26.0.2"
defaultConfig {
applicationId "co.newandroiddummy"
minSdkVersion 19
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
compile 'com.google.firebase:firebase-database:11.0.2'