有没有人在新的 Android Studio 4.1 中遇到过这个问题。当我将应用程序运行到模拟器时,一切正常并构建。后来它也显示一条消息
在运行中,错误信息是
Unable to determine application id: com.android.tools.idea.run.ApkProvisionException: Error loading build artifacts from: LOCATION/build/outputs/apk/act/debug/output-metadata.json
Run Code Online (Sandbox Code Playgroud) 我试图为 Room 创建一个数据类,该类还有一个仅用于视图的字段。我不想将数据保存到 Room 中。
@Entity(tableName = "MyTable")
@Parcelize
data class MyTable(
@SerializedName("id") @PrimaryKey val id: String,
@SerializedName("field1") val field1: String?,
var selected: Boolean? = false //todo use @Ignore
) : Parcelable
Run Code Online (Sandbox Code Playgroud)
上面的代码有效。但是,每当我尝试将@Ignore注释与变量一起使用时selected。它给了我以下错误
error: Entities and Pojos must have a usable public constructor. You can have an empty constructor or a constructor whose parameters match the fields (by name and type).
Run Code Online (Sandbox Code Playgroud)
如果我从构造函数中删除变量,例如
@Entity(tableName = "MyTable")
@Parcelize
data class MyTable(
@SerializedName("id") @PrimaryKey val id: String,
@SerializedName("field1") val …Run Code Online (Sandbox Code Playgroud) 我正在使用 Room 和 Kotlin 数据类。如,
@Entity(tableName = "Person")
@Parcelize
class Test(@ColumnInfo(name = "name") var name:String) : Parcelable{
@PrimaryKey(autoGenerate = true)
@ColumnInfo(name = "ID")
var id: Long? = null
}
Run Code Online (Sandbox Code Playgroud)
我可以使用构造函数创建实例并插入数据。我也收到警告"property would not be serialized into a 'parcel'"。当我试图通过一个包发送对象时,id 丢失了,正如警告所说的那样。如何ID在包裹中添加该成员?我没有在构造函数中保留 ID,因为我希望它们自动生成。
android parcelable kotlin kotlin-android-extensions android-room
我正在尝试使用身份验证器来处理 401 响应。我所做的是
fun provideAccessTokenAuthenticator(
mainApiServiceHolder: MainApiServiceHolder,
preferences: SharedPreferences
) = object : Authenticator {
override fun authenticate(route: Route?, response: Response): Request? {
val accessToken = preferences.getString(ACCESS_TOKEN, null)
if (!isRequestWithAccessToken(response) || accessToken == null) {
return null
}
synchronized(this) {
val newAccessToken = preferences.getString(ACCESS_TOKEN, null)!!
// Access token is refreshed in another thread.
if (accessToken != newAccessToken) {
return newRequestWithAccessToken(response.request, newAccessToken)
}
// Need to refresh an access token
val refreshTokenResponse = runBlocking {
Log.d("zzzzzzzzzz", "refresh token is running")
mainApiServiceHolder.mainApiService?.refreshToken( …Run Code Online (Sandbox Code Playgroud) 我相信还有很多类似的问题。但是,我找不到解决我遇到的问题的方法。问题是 popBackStack 函数从 backstack 中删除了片段。但是,当另一个新导航发生时,它会崩溃。我举个例子,我有三个片段,FragmentFirst、FragmentSecond 和 FragmentThird。一张导航图,
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/nav_a"
app:startDestination="@id/firstFragment">
<fragment
android:id="@+id/firstFragment"
android:name="com.example.myapplication.FirstFragment"
android:label="fragment_first"
tools:layout="@layout/fragment_first" >
<action
android:id="@+id/action_firstFragment_to_secondFragment"
app:destination="@id/secondFragment" />
</fragment>
<fragment
android:id="@+id/secondFragment"
android:name="com.example.myapplication.SecondFragment"
android:label="SecondFragment" >
<action
android:id="@+id/action_secondFragment_to_thirdFragment"
app:destination="@id/thirdFragment" />
</fragment>
<fragment
android:id="@+id/thirdFragment"
android:name="com.example.myapplication.ThirdFragment"
android:label="ThirdFragment" >
</fragment>
</navigation>
Run Code Online (Sandbox Code Playgroud)
第一个片段,
button.setOnClickListener {
findNavController().navigate(R.id.action_firstFragment_to_secondFragment)
}
Run Code Online (Sandbox Code Playgroud)
第二个片段,
button2.setOnClickListener {
view.findNavController().navigate(R.id.action_secondFragment_to_thirdFragment)
}
Run Code Online (Sandbox Code Playgroud)
第三个片段,
button3.setOnClickListener {
findNavController().popBackStack(R.id.firstFragment, true)
}
Run Code Online (Sandbox Code Playgroud)
现在,我可以从第一导航到第二,从第二导航到第三,从第三导航到第一。但是当我再次按下 First 中的按钮时,它崩溃了并且消息是
id/action_firstFragment_to_secondFragment cannot be found from the current destination NavGraph
Run Code Online (Sandbox Code Playgroud)
如果我在图中创建一个动作,例如,
<fragment
android:id="@+id/thirdFragment"
android:name="com.example.myapplication.ThirdFragment"
android:label="ThirdFragment" >
<action
app:popUpTo="@id/firstFragment"
app:popUpToInclusive="true"
android:id="@+id/action_thirdFragment_to_firstFragment"
app:destination="@id/firstFragment" …Run Code Online (Sandbox Code Playgroud) 我是Android新手.我一直在寻找一种方法来删除其他应用程序的权限.例如,我不希望应用程序发送短信.可能吗?
Thanx提前.
谢谢你的回复.
实际上,我正处于编码的中间,我想限制其他应用程序的清单权限.
由于这些应用存在于市场中,因此这是可能的.任何更多的帮助或任何参考将是如此有用.
再次.
是否有任何工具可以将 Vector Drawable 转换为 SVG?我丢失了原始 svg 文件,现在我想减小图像的大小。目前,我有,
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="1200dp"
android:height="1200dp"
android:viewportHeight="1200"
android:viewportWidth="1200">
Run Code Online (Sandbox Code Playgroud)
我想将其设为 180x180。提前致谢。
我正在尝试编写一个通用的 recyclerview 适配器。我找到了几个例子。然而,仍然无法弄清楚如何实现通用适配器。我写的代码是,
open abstract class BaseAdapter<T : RecyclerView.ViewHolder>(private val onClickListener: View.OnClickListener, @LayoutRes private val layoutResource:Int) :
RecyclerView.Adapter<T>() {
var items: MutableList<Item> = mutableListOf()
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): T {
val layout = LayoutInflater.from(parent.context).inflate(layoutResource, parent, false)
layout.setOnClickListener(onClickListener)
return T(layout)
}
override fun getItemCount(): Int {
return items.size
}
}
Run Code Online (Sandbox Code Playgroud)
我在 line 处收到错误return T(layout)。错误是Expression 'T' of type 'Int' cannot be invoked as a function. The function 'invoke()' is not found。
我有一个如下表所示的模型,
create table `mytable`
(
`person` varchar(10),
`groupname` int,
`age` int
);
Run Code Online (Sandbox Code Playgroud)
我想从每组中选出 2 个最年长的人。原始的 SQL 问题和答案在这里StackOverflow,有效的解决方案之一是
SELECT
person,
groupname,
age
FROM
(
SELECT
person,
groupname,
age,
@rn := IF(@prev = groupname, @rn + 1, 1) AS rn,
@prev := groupname
FROM mytable
JOIN (SELECT @prev := NULL, @rn := 0) AS vars
ORDER BY groupname, age DESC, person
) AS T1
WHERE rn <= 2
Run Code Online (Sandbox Code Playgroud)
您也可以在此处检查 SQL 输出以及SQLFIDLE
我只是想知道如何在 Django 视图中将这个查询实现为查询集。
jetpack compose 中是否有任何替代方案announceForAccessibility可以自动宣布事件的文本。
android ×10
kotlin ×3
android-room ×2
android-architecture-navigation ×1
django ×1
django-orm ×1
generics ×1
java ×1
okhttp ×1
parcelable ×1
permissions ×1
retrofit2 ×1