小编Dan*_*iel的帖子

手机重置后,不会触发AlarmManager闹钟

在我的应用程序中,用户加入计划,然后第二天中午会有一个警报通知.这是我的代码:

首先,我在AlarmManager中设置一个警报,如下所示:

//set alarm to the next day 12:00 noon of the join date
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");  
try {  
    alarm_date = format.parse(join_date);
} catch (ParseException e) {  
    e.printStackTrace();  
}

GregorianCalendar calender = new GregorianCalendar();
calender.setTime(alarm_date);
calender.add(Calendar.DATE, 1);
calender.add(Calendar.HOUR_OF_DAY, 12);
//calender.add(Calendar.HOUR_OF_DAY, 14); //temp testing data
//calender.add(Calendar.MINUTE, 43);

AlarmManager am = (AlarmManager) ctx.getSystemService(Context.ALARM_SERVICE);
Intent i = new Intent(ctx, AlarmReceiver.class);
am.set(AlarmManager.RTC_WAKEUP, calender.getTimeInMillis(), PendingIntent.getBroadcast(ctx, 1, i, PendingIntent.FLAG_UPDATE_CURRENT));
Run Code Online (Sandbox Code Playgroud)

然后,在预定的时间,它会触发接收器,如下所示:

public class AlarmReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) { …
Run Code Online (Sandbox Code Playgroud)

android alarm alarmmanager android-alarms

2
推荐指数
1
解决办法
1703
查看次数

如何使用Dagger2将ApplicationContext注入非活动类?

我有几个我想注入的课程.例如,我有一个APIContentLoader类,用于从端点下载JSON,然后将其存储到数据库中.我想将我用于读/写数据库的DatabaseManager类注入到APIContentLoader中.为了将DatabaseManager注入此类,我首先需要对ApplicationContext的引用,对吗?

这就是我现在设置的方式:

public class APIContentLoader{
    @Inject DatabaseManager dbm;
    @Inject BaseApplication app;

    public APIContentLoader(){
        app.getAppComponent().inject(this);
        // dbm now is ready for use
    }  
    ... // rest of class stuff
}
Run Code Online (Sandbox Code Playgroud)

我的BaseApplication类扩展了标准的Application类.以这种方式向这个类注入BaseApplication引用是不好的做法?我知道对ApplicationContext进行静态引用并不是将它们提供给这些非活动类的好方法.

我想最重要的问题是,这种方法是否存在与内存管理相同的静态引用问题,并持续存在这些辅助类的生命周期?

android dagger-2 android-application-class

2
推荐指数
1
解决办法
1719
查看次数

如何使用动画将按钮的形状从圆角矩形更改为圆形

我的活动中有一个圆角矩形按钮。单击按钮后,它应该稍微压缩/收缩(按钮的高度不应改变),并且它应该变为圆形。如何使用 XML 中的 anim 文件夹实现此目的?

目前我的代码是:

<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:fillAfter="true">
    <scale
        android:duration="400"
        android:fromXScale="1"
        android:fromYScale="1"
        android:pivotX="50%"
        android:toXScale="0.1"
        android:toYScale="1" />
    <set>
        <alpha
            android:duration="400"
            android:fromAlpha="1"
            android:toAlpha="0" />
    </set>
</set>
Run Code Online (Sandbox Code Playgroud)

android

2
推荐指数
1
解决办法
2402
查看次数

android mediaSession getPosition() 总是返回 0

我正在尝试获取当前位置,以便我可以在我的媒体播放器应用程序中推进搜索栏。但是,每次我打电话:

getSupportMediaController().getPlaybackState().getPosition();
Run Code Online (Sandbox Code Playgroud)

如果媒体正在播放,则返回 0,如果媒体暂停,则返回 -1。我搜索了很多没有成功的解决方案,我尝试了一切。

顺便说一下,我将上面的代码放在一个 runner 中,以便它每 1 秒执行一次。

android runnable android-mediaplayer android-seekbar android-mediasession

2
推荐指数
1
解决办法
1170
查看次数

php artisan migrate - 错误 - Illuminate\Database\QueryException : SQLSTATE[HY000] [2054]

执行时出现以下错误:

php artisan migrate
Run Code Online (Sandbox Code Playgroud)

错误:

Illuminate\Database\QueryException : SQLSTATE[HY000] [2054] 服务器请求客户端未知的身份验证方法(SQL:select * from information_schema.tables where table _schema = d1 and table_name = migrations)

这是一个截图;

在此处输入图片说明

附注。以防万一:我在php.ini文件中启用了“extension=pdo_mysql” 。

任何想法如何解决这一问题?

php migrate laravel-artisan

2
推荐指数
2
解决办法
2万
查看次数

vue路由器同页刷新

我想从以下 URL http://localhost:8081/#/scenarios/SCNRF3SZ2FS54E66B456转到此 URL http://localhost:8081/#/scenarios/SCNRF3XAPLPJ241807A9。但它不起作用,代码如下:

export default new Router({
   mode: 'hash',
   linkActiveClass: 'open active',
   scrollBehavior: () => ({ y: 0 }),
   routes: [
     {
       path: '/',
       redirect: '/scenarios/:id',
       component: Full,
       beforeEnter: beforeEnter,
       children: [{
       path: '/scenarios/:id',
       name: 'Scenario',
       component: Scenario
     }]
   }
  ]
 })
Run Code Online (Sandbox Code Playgroud)

我该如何让它发挥作用?

vue.js vue-router vuejs2

2
推荐指数
1
解决办法
2万
查看次数

如何更改 AlarmManager 警报?

AlarmManager在我的应用程序中使用在适当的时间设置闹钟。我的应用程序中有多个闹钟,因此每次用户保存闹钟时,我都会找到下一次应该播放哪个闹钟,并将该闹钟的 ID 作为额外意图传递。这是我使用的代码:

Intent intent = new Intent(this, AlarmBroadcastReceiver.class);
intent.putExtra("alrmId", finalAlr);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 56, intent, 0);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); 
alarmManager.cancel(pendingIntent);
alarmManager.set(AlarmManager.RTC_WAKEUP, (System.currentTimeMillis() + (finalAlrDay * 24 * 60 * 60 * 1000) + (finalAlrHr * 60 * 60 * 1000) + (finalAlrMin * 60 * 1000) + (finalAlrSec * 1000)), pendingIntent);
Run Code Online (Sandbox Code Playgroud)

在这里,如果有任何旧的闹钟设置,我会取消,然后添加新的闹钟。所有闹钟都在正确的时间播放,但问题是alrmId我设置的值intent.putExtra始终与我第一次设置时的值相同。

例如,如果我第一次设置闹钟并且当时alrmId设置为“1”,那么无论我之后输入什么值,它都将始终保持不变。我试过调试它,我确保它intent.putExtra("alrmId", finalAlr)输入了正确的值,所以这不是问题。问题是什么?

android alarmmanager android-intent

1
推荐指数
1
解决办法
1699
查看次数

ndarray 比 rearray 访问更快吗?

我能够将重新阵列数据复制到 ndarray,进行一些计算并返回具有更新值的 ndarray。

然后,我发现了append_fields()中的功能numpy.lib.recfunctions,并认为简单地将 2 个字段附加到我的原始重新数组来保存我的计算值会更聪明。

当我这样做时,我发现操作速度慢得多。我不需要计时,基于 ndarray 的过程需要几秒钟,而使用 recarray 需要一分钟以上,而且我的测试数组很小,<10,000 行。

这是典型的吗?ndarray 访问比 rearray 快得多?我预计由于按字段名称访问会导致性能下降,但不会那么多。

python field numpy append recarray

0
推荐指数
1
解决办法
1046
查看次数

Koin依赖注入

我有一个使用Dagger 2进行依赖注入的类。现在我想切换到Koin进行依赖注入。Koin中有模块,我想在课堂之外制作一个模块,或者什么都可以做。

@Module
class NetModule(private val baseUrl: String) {

@Provides
@Singleton
fun providesOkHttpClient(
        httpLoggingInterceptor: HttpLoggingInterceptor): OkHttpClient = OkHttpClient.Builder().addInterceptor(
        httpLoggingInterceptor).build()

@Provides
@Singleton
fun provideLoggingInterceptor(): HttpLoggingInterceptor {
    val interceptor = HttpLoggingInterceptor(
            HttpLoggingInterceptor.Logger { message -> Logger.d("NETWORK: $message") })
    interceptor.level = HttpLoggingInterceptor.Level.NONE
    return interceptor
}

@Provides
@Singleton
fun providesMoshi(): Moshi = Moshi.Builder().add(KotlinJsonAdapterFactory()).build()

@Provides
@Singleton
fun providesRetrofit(okHttpClient: OkHttpClient, moshi: Moshi): Retrofit {
    return Builder().client(okHttpClient).baseUrl(baseUrl)
            .addConverterFactory(GsonConverterFactory.create())
            .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
            .build()
}

@Provides
@Singleton
fun providesApiInterface(retrofit: Retrofit): ApiInterface = retrofit.create(
        ApiInterface::class.java)
}
Run Code Online (Sandbox Code Playgroud)

android kotlin koin

0
推荐指数
1
解决办法
621
查看次数