new Thread(new Runnable(){
}).run();
Run Code Online (Sandbox Code Playgroud)
VS
new AsyncTask().execute();
Run Code Online (Sandbox Code Playgroud)
我的印象是他们是同一个东西,都开始了新的工作线程,但事实并非如此吗?
我问的原因是因为如果我尝试使用任何类型的网络连接new Thread()我得到一个NetworkOnMainThreadException但是当我在异步任务中放入相同的代码时,我没有得到它.
这个差异的另一个例子是使用google maps api v2,其中所有的情节/显示/隐藏必须在上面进行,main thread但是如果我new Thread()用来隐藏/显示标记,那么看起来很好但是如果我尝试在异步任务中显示/隐藏我得到一个例外,说它需要在主线程上完成.
它new Thread()真的不启动辅助线程?
编辑
不知道为什么这个被关闭,因为提供的链接我已阅读并没有回答我的问题,并没有提到使用run()vs start()回答我的问题
我有一种方法可以将地图缩放到用户指定的缩放级别,但不会使用缩放 CameraUpdateFactory.zoomTo(9f);
但是,如果我这样做,它将正确缩放
CameraPosition position = new CameraPosition.Builder().target(location).zoom(9).build();
map.animateCamera(CameraUpdateFactory.newCameraPosition(position));
Run Code Online (Sandbox Code Playgroud)
但这需要我有一个缩放的位置.
根据文档看起来我只是zoomTo静态地访问该方法但是当我这样做时没有任何反应.
我错误地使用第一种方法吗?
我们将如何从Google云端存储中获取视频并将其流式传输到移动设备?
我没有看到与视频相关的任何内容,Java API例如通过ImagesServiceFactory
如果有任何区别,则视频最长只能有10-15秒。
关于如何进行此处的任何建议都很好
google-app-engine android google-cloud-storage google-cloud-platform
在Swift 3中,我收到以下错误(在Swift 2中没有发生):
No*candidate产生预期的结果类型FloatingPointRoundingRule
我不知道我需要做些什么来修复它.
我想将纬度小数转换为度/分/秒
extension CLLocationDegrees {
mutating func toLatitudeSeconds() -> String {
var seconds = Int(round(self * 3600)) //error here
// etc ...
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个 Lottie 动画,我想启动它,然后当它到达某个帧时,我想从 X 帧循环到 Y 帧。
我遇到的问题是我似乎无法弄清楚如何clipSpec在运行时更新LottieComposeasclipSpec无法重新分配。
我能够使用基于 Lottie 的普通 XML 布局来做到这一点,没有任何问题,如下所示
loading_animation.addAnimatorUpdateListener {
if(initialLoad && loading_animation.frame == 15){
initialLoad = false
startTime = System.currentTimeMillis()
loading_animation.setMinAndMaxFrame(15,28)
}
if(!initialLoad && authenticated && System.currentTimeMillis() >= (startTime+1000)){
loading_animation.pauseAnimation()
startActivity()
}
}
Run Code Online (Sandbox Code Playgroud)
这是我LottieCompose到目前为止的代码
val composition by rememberLottieComposition(LottieCompositionSpec.RawRes(R.raw.sun_icon))
val animatable = rememberLottieAnimatable()
val progress by animateLottieCompositionAsState(composition, iterations = LottieConstants.IterateForever)
LottieAnimation(composition = composition, progress = progress, modifier = Modifier.wrapContentSize())
Run Code Online (Sandbox Code Playgroud) 我想要完成的是在每一行中都有一个复选框,能够单独选中该框(用于批量删除),并能够选择整行来查看与列表项关联的数据.
我已经完成了一个带有textview的复选框,但只允许选择框,我无法点击列表项来查看该项数据.我也用过,checkedTextView但是检查一下你点击行调用的那个盒子,那onListItemClick不是我想要的.是否有一些我可以单独检查框中的单击列表视图项目?
gmail在选择要删除和查看的消息时,几乎尝试做应用程序所做的事情
这是我的行布局
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"/>
<TextView
android:id="@+id/nameCheckTV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/checkBox1"
android:layout_toRightOf="@+id/checkBox1"
android:paddingTop="5dp"
android:paddingLeft="15dp"
android:text="Name"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
创建列表视图
@Override
public void onActivityCreated(Bundle state){
super.onActivityCreated(state);
lv = getListView();
lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
lv.setItemsCanFocus(false);
setEmptyText("No Bowlers");
registerForContextMenu(getListView());
populateList();
}
Run Code Online (Sandbox Code Playgroud)
编辑:
我的填充方法
public void populateList(){
String[] fields = new String[] {BowlersDB.NAME};
//mAdapter = new CheckAdapter(getActivity(),R.layout.check_listview,null,fields,new int[] {R.id.nameCheckTV});
mAdapter = new SimpleCursorAdapter(getActivity(),R.layout.check_listview,null,fields,
new int[] {R.id.nameCheckTV});
setListAdapter(mAdapter);
getLoaderManager().initLoader(0,null,this);
}
Run Code Online (Sandbox Code Playgroud) 用户在执行下面的代码时在手机上收到错误,我在运行AsyncTaskWeb服务调用之前检查用户当前是否正在通话.我这样做的原因是因为有些人在通话时失去了互联网连接,所以我每5秒检查一次是否正在通话.如果不是,则调用AsyncTask
do{
Handler handler = new Handler();
handler.postDelayed(new Runnable(){
@Override
public void run() {
onCall = ((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE))
.getCallState() != TelephonyManager.CALL_STATE_IDLE;
if(!onCall){
new CallRegWS().execute();
}
}
},5000);
}while(onCall);
Run Code Online (Sandbox Code Playgroud)
我没有完整的堆栈跟踪只显示错误
java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
Run Code Online (Sandbox Code Playgroud)
显然不是太有帮助,但这就是我必须继续下去.他们不断得到这个错误,所以当我创建处理程序时必须发生这种错误.
所有这一切都是在main thread所以我不知道问题是什么,任何洞察我如何解决这个问题?
从服务调用此更新,该方法位于单独的类中
假设我有一个电子邮件地址字符串,"John Smith" <JSmith@gmail.com>我想要的只是获取电子邮件地址<>
我怎么会这样做而没有得到其他一切?
我正在尝试向我的数据库添加一些内容,但我一直收到错误消息,指出列不存在.我查看了使用的表格root explorer,它只创建了前两列的id和name.这就是我最初在那里所有的,但后来我添加了几个列,现在它甚至在我完成程序的全新安装后也给了我错误.
它是一个内容提供商,如果重要的话
12-08 16:55:21.470: E/SQLiteDatabase(23282): Error inserting series=0 team_pos=0 handed=0 name=Allen, Andrew substitute=0 game=0 team=0 average=0
12-08 16:55:21.470: E/SQLiteDatabase(23282): android.database.sqlite.SQLiteException: table bowlers_table has no column named series: , while compiling: INSERT INTO bowlers_table(series,team_pos,handed,name,substitute,game,team,average) VALUES (?,?,?,?,?,?,?,?)
12-08 16:55:21.470: E/SQLiteDatabase(23282): at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
12-08 16:55:21.470: E/SQLiteDatabase(23282): at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:64)
12-08 16:55:21.470: E/SQLiteDatabase(23282): at android.database.sqlite.SQLiteProgram.compileSql(SQLiteProgram.java:146)
12-08 16:55:21.470: E/SQLiteDatabase(23282): at android.database.sqlite.SQLiteProgram.compileAndbindAllArgs(SQLiteProgram.java:367)
12-08 16:55:21.470: E/SQLiteDatabase(23282): at android.database.sqlite.SQLiteStatement.acquireAndLock(SQLiteStatement.java:253)
12-08 16:55:21.470: E/SQLiteDatabase(23282): at android.database.sqlite.SQLiteStatement.executeInsert(SQLiteStatement.java:111)
12-08 16:55:21.470: E/SQLiteDatabase(23282): at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1737)
12-08 16:55:21.470: …Run Code Online (Sandbox Code Playgroud) 我正在尝试导入我存储在SD卡上的数据库,我用它作为备份来替换当前数据库,如果我想恢复某些东西但是当我尝试导入时我得到了一个 NonWritableChannelException
错误
12-15 12:27:48.190: W/System.err(13599): java.nio.channels.NonWritableChannelException
12-15 12:27:48.190: W/System.err(13599): at java.nio.FileChannelImpl.checkWritable(FileChannelImpl.java:85)
12-15 12:27:48.190: W/System.err(13599): at java.nio.FileChannelImpl.transferTo(FileChannelImpl.java:399)
12-15 12:27:48.190: W/System.err(13599): at com.tyczj.bowling.Bowlers$ImportData.importGames(Bowlers.java:944)
12-15 12:27:48.200: W/System.err(13599): at com.tyczj.bowling.Bowlers$ImportData.doInBackground(Bowlers.java:914)
12-15 12:27:48.200: W/System.err(13599): at com.tyczj.bowling.Bowlers$ImportData.doInBackground(Bowlers.java:1)
12-15 12:27:48.200: W/System.err(13599): at android.os.AsyncTask$2.call(AsyncTask.java:287)
12-15 12:27:48.200: W/System.err(13599): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
12-15 12:27:48.210: W/System.err(13599): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
12-15 12:27:48.210: W/System.err(13599): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
12-15 12:27:48.210: W/System.err(13599): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
12-15 12:27:48.210: W/System.err(13599): at java.lang.Thread.run(Thread.java:856)
Run Code Online (Sandbox Code Playgroud)
这是我用来导入的方法
public boolean importGames(){
File newDB = new File(Environment.getExternalStorageDirectory() + "/BCAData/Games");
File oldDB = new File(Environment.getDataDirectory()+"/data/my.app.package/databases/Games");
if(newDB.exists()){
try …Run Code Online (Sandbox Code Playgroud) 我的主要活动有一个NavigationDrawer,在一个实例中我显示了一个片段,"汉堡菜单"变成了一个箭头.
当使用此片段显示该片段时,我禁用了通过滑动打开抽屉的功能
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
Run Code Online (Sandbox Code Playgroud)
它工作正常但现在问题是用户仍然可以通过单击主页按钮"箭头"打开抽屉.我希望箭头作为后退按钮而不打开抽屉,这样我怎么能阻止抽屉打开?