我试图使用Notification.Builder.setLargeIcon(bitmap)带有位图图像.我有我想在可绘制文件夹中使用的图像,那么如何将其转换为位图?
null string(String s = null)和空字符串(String s = "")之间有什么区别?
这就是我所拥有的:
String s1 = ""; //print statement does not print any thing for s1 but s1.length()=0
String s2 = null;//print statement prints "null" for s2 but s2.length() gives exception
Run Code Online (Sandbox Code Playgroud)
这是什么意思?
我们可以在finally块中使用return语句.这会导致任何问题吗?
每当我创建任何应用程序时,我总是对字符串进行硬编码,而不是从XML中的字符串资源引用它.应用程序工作正常,但让我警告使用@string资源
示例按钮:
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="click here" />
Run Code Online (Sandbox Code Playgroud)
我的问题是,如果我这样做或者它(@string资源)仅用于国际化,它是否会影响我的应用程序性能.
我正在使用min SDK构建一个Android应用程序15,它使用的是OpenCV库.问题是当我构建apk时,它的大小超过60MB而且不是很好.
我检查了应用程序文件,我可以看到的是,规模过大,由于libopencv_java3.so在像所有架构文件amr64,armeabi,mips,x86等.
我只使用opneCv进行图像处理.这个库还有许多其他功能,如视频处理,3D图像,对象检测等等,我不需要在我的应用程序中使用
如果我删除所有这些文件并构建APK,那么大小将减少50 MB,但为了使这个应用程序工作,我需要安装OpenCVManager来运行我的应用程序.
有什么方法可以减少我的apk大小?
或者只是提取OpenCV我感兴趣的功能并.so为这些功能创建?
java-native-interface android opencv native image-processing
我有一个活动,我定期更改ImageView,因为我编写了下面的代码行.
imageview.setImageUri(resId);
Run Code Online (Sandbox Code Playgroud)
我正在增加资源ID.它工作正常但是从一个图像突然转换到另一个图像.我不希望这样,我希望图像视图平滑过渡到另一个图像.我怎样才能做到这一点?
如果我与我的应用程序进行交互(使用),我有一个警报可以正常工作,但是如果我将它设置为第二天并且不与我的应用程序进行交互则它不起作用.因此我怀疑这是因为我的应用程序进程没有运行那时候.
这就是我在做什么
Calendar calSet = Calendar.getInstance();
calSet.set(Calendar.HOUR_OF_DAY, selectedhour);
calSet.set(Calendar.MINUTE, selectedminute);
calSet.set(Calendar.YEAR, year);
calSet.set(Calendar.MONTH, monthOfYear);
calSet.set(Calendar.DATE, dayOfMonth);
alarm = new Intent(ActivityA.this, Service.class);
pendingIntent = PendingIntent.getService(getApplicationContext(), i++,alarm, 1);
alarmanager.set(AlarmManager.RTC_WAKEUP, calSet.getTimeInMillis(),pendingIntent);
Run Code Online (Sandbox Code Playgroud) 在浏览android开发者网站时,我发现了这一点
.
它说为了避免内存泄漏我们应该在onStop()中释放资源但是如何这样做.
我有一个成功运行的 appwidget。现在,当手机重新启动时,小部件会丢失所有数据并仅位于主屏幕上。由于我无法在手机重新启动时从广播接收器更新小部件,因此我创建了一个通知,该通知会导致小部件的配置活动。用户再次设置配置并离开配置活动后,一切都不起作用;空闲小部件仍然存在?(用户必须删除小部件并再次创建小部件)。我假设我没有正确接收小部件 id 或者我在广播接收器中做错了,并假设将所有代码移动到onEnable 在小部件方法中?.. 我如何正确刷新小部件。请记住,所有小部件更新都是通过服务完成的。
顺便说一下,我在广播接收器中有这个代码用于 boot_completed 操作:
public void onReceive(final Context context, Intent intent) {
String info = context.getResources().getString(R.string.restart_setting);
int[] allids = AppWidgetManager.getInstance(context).getAppWidgetIds(new ComponentName(context, MyWidgetProvider.class));
for(int appWidgetId:allids){
NotificationManager mnotifyManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notify = new Notification(R.drawable.icon, "Weather Update", System.currentTimeMillis());
notify.defaults = Notification.DEFAULT_SOUND;
notify.defaults = Notification.DEFAULT_VIBRATE;
Intent Settings = new Intent(context, WidgetConfigure.class);
Settings.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
PendingIntent pending = PendingIntent.getActivity(context, 0, weatherSettings, PendingIntent.FLAG_ONE_SHOT);
notify.setLatestEventInfo(context, "Weather Update", info, pending);
notify.flags = Notification.FLAG_AUTO_CANCEL;
notify.defaults = Notification.DEFAULT_ALL;
mnotifyManager.notify(WEATHER_NOTIFICATION_ID , notify);
}
}
Run Code Online (Sandbox Code Playgroud) 问题是,在我使用内置的任务管理器的清理内存/内存后,我的小部件停止工作。我想这与任务管理器清理内存的方法有关。经过大量研究和一些尝试,我发现我需要BroadcastReciever 侦听包更改和更新:所以我实现了但它不起作用,因为文档说已that the 重新启动/已清除 package does not receive this broadcast
在清单文件中注册接收器:
<receiver android:name="com.app.lab.receiver.onRestartReciever">
<intent-filter>
<action android:name="android.intent.action.PACKAGE_REPLACED" />
<action android:name="android.intent.action.PACKAGE_RESTARTED" />
<action android:name="android.intent.action.PACKAGE_DATA_CLEARED"/>
<data android:scheme="package" />
</intent-filter>
Run Code Online (Sandbox Code Playgroud)
PACKAGE_REPLACED - 特别调用以通知应用程序更新。
PACKAGE_RESTARTED - 当大多数内存清理器正在清理内存时调用。
“数据”行用于监视应用于特定包的操作。
public class onRestartReciever extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
Log.d("DEBUG", "onRestartReciever");//I am not getting this log on clearing memory from task manager
}
}
Run Code Online (Sandbox Code Playgroud)
我尝试使用虚拟服务来获取其生命周期,即检查 onDestroy 何时被调用,但我发现它不是一种可靠的方法,当应用程序被任务管理器杀死时,可能不会调用 onDestroy。
所以最后,我的问题 是:当任务管理器或操作系统清理内存时,有什么方法可以告诉 android 系统重新启动 …
android ×8
java ×2
performance ×2
alarmmanager ×1
bitmap ×1
calendar ×1
finally ×1
memory-leaks ×1
native ×1
null ×1
opencv ×1
string ×1