我用于传递意图的 Firebasemessagingservice 类代码:
private void showNotification(String message){
Intent intent=new Intent(this, DrawerActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("data", message);
PendingIntent pendingIntent=PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder builder=new NotificationCompat.Builder(this)
.setAutoCancel(true)
.setContentTitle("Registry")
.setContentText(message)
.setSmallIcon(R.drawable.com_facebook_button_send_icon_blue)
.setContentIntent(pendingIntent);
NotificationManager manager=(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
manager.notify(0,builder.build());
}
Run Code Online (Sandbox Code Playgroud)
我在 onCreate() 方法中的 Fragment BaseActivity 代码:
Intent notifyIntent = getIntent();
Bundle extras = notifyIntent.getExtras();
if (extras != null) {
replacefragment code;
}
Run Code Online (Sandbox Code Playgroud)
它不工作..
为什么在运行应用程序时总是会出现NullPointerException?每次我启动我的genymotion模拟器,然后第一次运行应用程序,它崩溃,但第二次我运行我的应用程序工作顺利.我不知道为什么它会在第一次运行时发生.
这是我的Splash屏幕,它从RetrieveGamesBGTask中检索JSON对象:
public class Splash extends Activity {
RetrieveGamesBGTask retrieveGamesBGTask;
String json_string;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
Thread thread = new Thread(){
@Override
public void run() {
try {
retrieveGamesBGTask = new RetrieveGamesBGTask();
retrieveGamesBGTask.execute();
sleep(3000);
Intent intent = new Intent(getApplication(), Games.class);
intent.putExtra("json_data", json_string);
intent.putExtra("json_data", retrieveGamesBGTask.getResult());
startActivity(intent);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
};
thread.start();
Run Code Online (Sandbox Code Playgroud)
这是下一个应用程序,它在第一次运行时每次崩溃:
retrieveGamesBGTask = new RetrieveGamesBGTask();
retrieveGamesBGTask.execute();
Intent intent = this.getIntent();
if (intent != null) {
json_string = intent.getStringExtra("json_data");
}
try { …Run Code Online (Sandbox Code Playgroud) 错误:(1,0)android gradle插件版本2.3.0-alpha1太旧了,请更新到最新版本.
要从命令行覆盖此检查,请将ANDROID_DAILY_OVERRIDE环境变量设置为"7e7deaebeebf38c3d877c687336265b8c39674f5"
知道我应该使用什么Gradle插件版本?我在金丝雀频道使用Android Studio 2.3 Beta 1.
我有以下问题.我需要验证日期和时间,因此如果星期几是星期二或星期四,并且时间是2:00到3:00 PM ,则返回false .
我有两个选择:
if (appointmentRequest.getDateTime().getDayOfWeek() == DayOfWeek.TUESDAY
|| appointmentRequest.getDateTime().getDayOfWeek() == DayOfWeek.THURSDAY) {
if (appointmentRequest.getDateTime().getHour() == 2) {
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
选项2:
if ((appointmentRequest.getDateTime().getDayOfWeek() == DayOfWeek.TUESDAY
|| appointmentRequest.getDateTime().getDayOfWeek() == DayOfWeek.THURSDAY)
&& (appointmentRequest.getDateTime().getHour() == 2)) {
return false;
}
Run Code Online (Sandbox Code Playgroud)
在这种情况下,最佳做法是什么?