小编sha*_*anu的帖子

在Android Studio中找不到符号类

我有两个项目A和B,其中B被添加为项目A的模块.我在A的Gradle构建文件中添加了依赖项.现在我可以在A中导入B的类而没有任何错误(在编辑器中)但无法构建.偏好是一类项目B.

错误

Error:(22, 23) error: cannot find symbol class Preferences 
Run Code Online (Sandbox Code Playgroud)

一个构建文件

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.0.0"

    defaultConfig {
        applicationId "com.example.A"
        minSdkVersion 9
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.0.3'
    compile project(':B')
}
Run Code Online (Sandbox Code Playgroud)

B的构建文件

import org.apache.tools.ant.taskdefs.condition.Os

apply plugin: "android-library"

android {
    compileSdkVersion 18
    buildToolsVersion "21.0.0"

    defaultConfig {
        minSdkVersion 9
        targetSdkVersion 11
    }

    buildTypes {
        release { …
Run Code Online (Sandbox Code Playgroud)

android android-studio android-gradle-plugin

18
推荐指数
3
解决办法
4万
查看次数

清除活动堆栈并在android中启动新活动

我的问题与这类问题略有不同.我需要删除或清除我的活动堆栈,然后开始一项新活动.我不认为这是一个clear_top标志问题.我正在解释一个例子:

我的活动流程:

Login > Home > Screen1 > screen2 ....
Run Code Online (Sandbox Code Playgroud)

我完成登录活动或使用no_history标志调用.所以我的活动看起来像这样

Login(finished)> Home [bottom of the stack now] > Screen1 > Screen2[top of the stack]
Run Code Online (Sandbox Code Playgroud)

我需要处理会话错误.如果在任何点发生任何会话错误,我需要返回登录活动.但请记住,我没有堆栈中的登录活动.所以clear_top不起作用.

如果在Screen2中发生任何会话错误,那么我需要清除完整堆栈(screen2,screen1,home),然后开始登录活动.因此,在返回按钮后按下登录活动将关闭我的应用程序.

有没有办法清除活动堆栈?

提前致谢

android android-activity

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

在 kotlin 中从 GSON 生成对象时不会调用数据类 init 函数

我正在使用Gsson转换JSON to Kotlin data class. 在创建数据类对象时,我想解析init方法中的值。但init从未调用和生成的对象的值为空。

data class Configuration (val groupId:Int, val key:String, val source:String){
    val query:String
    val search:String
    init {
        val obj = JSONObject(key)
        query = obj.getString("q")
        search = obj.getString("search")
    }
}
Run Code Online (Sandbox Code Playgroud)

当我配置的从对象Gsonquerysearch值始终nullinit永远不会执行块。我也试过 constructor 没有data关键字,结果是一样的。

kotlin data-class

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

活动结束后通知消失

我有一个名为A从a开始的活动broadcast receiver.活动A触发了通知,但在活动销毁(完成)时它会自动消失.但我想保留此通知,直到用户单击或手动清除通知.

活动如何从广播接收器开始

Intent i = new Intent(context,A.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
i.putExtras(intent.getExtras());
context.startActivity(i);
Run Code Online (Sandbox Code Playgroud)

通知

Intent notificationIntent = new Intent();
notificationIntent.setClass(context,B.class);
notificationIntent.setAction(Intent.ACTION_MAIN);
notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER);
notificationIntent.setFlags( Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
Notification notification = new NotificationCompat.Builder(context)
        .setSmallIcon(R.drawable.notification_small)
        .setContentTitle(status)
        .setTicker(status)
        .setAutoCancel(false)
        .setContentText(message)
        .setDefaults(Notification.DEFAULT_SOUND)
        .setLargeIcon(
                Bitmap.createScaledBitmap(icon, 128, 128, false))
        .setContentIntent(pendingIntent)
        .build();
Run Code Online (Sandbox Code Playgroud)

清单选项

<activity android:name="com.example.activity.A"
android:screenOrientation="portrait"
android:launchMode="singleTask"
android:taskAffinity=""
android:excludeFromRecents="true"/>
Run Code Online (Sandbox Code Playgroud)

注意:我也尝试过singleInstance,但没有运气.

编辑(固定)

我犯了一个愚蠢的错误.我调用了clearAll()而不是取消onDestroy()函数中的特定通知.

android android-manifest android-notifications

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

在一个文件中运行Jython和Python

我用python开发了一个项目.现在我需要一个gui用于该项目.所以我选择jython for gui(java swing).我还将主题集成在一个代码中(现有项目+ gui(jython)代码).当我使用以下命令运行该文件时,它显示语法错误

jython project.py
Run Code Online (Sandbox Code Playgroud)

错误:

File "project.py", line 33
SyntaxError: 'with' will become a reserved keyword in Python 2.6
Run Code Online (Sandbox Code Playgroud)

线#33:

32 def _finished_loading(self, view, frame):
33        with open(self._file, 'w') as f:
Run Code Online (Sandbox Code Playgroud)

当我使用python命令运行现有项目时,它运行正常.这意味着该项目没有问题.我向你保证gui(jython)代码和集成也很好.

python jython

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

添加帐户(设置)方法无法启动Activity

我想在设置中创建自定义应用帐户.

问题

  1. 有一个图标settings > Add account但没有名称的选项
  2. 单击该(添加帐户)时,AuthenticatorActivity无法启动.我调试Authenticator类,addAccount调用方法但没有弹出任何活动.

我做了以下步骤:

认证类(部分)

public class AccountAuthenticator extends AbstractAccountAuthenticator{
    @Override
    public Bundle addAccount(AccountAuthenticatorResponse response,
            String accountType, String authTokenType,
            String[] requiredFeatures, Bundle options)
            throws NetworkErrorException {
        final Intent intent = new Intent(mContext, AuthenticatorActivity.class);
        intent.putExtra(AuthenticatorActivity.ARG_ACCOUNT_TYPE, accountType);
        intent.putExtra(AuthenticatorActivity.ARG_AUTH_TYPE, authTokenType);
        intent.putExtra(AuthenticatorActivity.ARG_IS_ADDING_NEW_ACCOUNT, true);
        intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response);
        final Bundle bundle = new Bundle();
        bundle.putParcelable(AccountAuthenticator.KEY_INTENT, intent);
        return bundle;
    }
}
Run Code Online (Sandbox Code Playgroud)

AuthenticatorService

public class AuthenticatorService extends Service{
     @Override
    public IBinder onBind(Intent intent) {
        authenticator = new …
Run Code Online (Sandbox Code Playgroud)

account android

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

AppCompat主题为Android TV应用程序

我是电视布局设计的新手.据参考,电视应用Leanback广泛使用主题系统,并提供一些专门为电视开发的小部件和类.但Leanback功能非常有限.

我想创建一个TabLayout由其提供的布局AppCompact.为此,活动必须使用,AppCompact theme但在片段我使用BrowserFragment提供Leanback.因此,当我添加AppCompact活动时,片段崩溃与布局参数问题.

Binary XML file line #21: Binary XML file line #21: You must supply a layout_width attribute.
Run Code Online (Sandbox Code Playgroud)

是不是可以在电视应用中使用这两个主题?

android television

5
推荐指数
0
解决办法
549
查看次数

如何在Android Studio中维护多个google-service.json

我正在使用Google Analytics哪个有google-services.json文件.但现在我已经添加了Firebase(而不是分析服务)另一个google-services.json.

我检查了两个JSON文件,client是一个JSON数组,所以我可以添加项目到旧​​,google-services.json但两个文件都有project_info不同的JSON对象.

如何将这些文件合并到一个文件中?或者是否有可能为两个谷歌服务指出两个不同的文件?

android json google-analytics firebase

5
推荐指数
0
解决办法
736
查看次数

关于昏迷服务器的困惑

我需要的是,我将打开一个UDP监听X端口(本地机器)的服务器,并且 machine(public IP)可以向UDP我发送数据包.我的机器没有public IP.基本上我需要stun.

我正在测试stuntman服务器/客户端项目.我在服务器(公共IP)中运行stuntman-server.在我的系统中运行客户端(本地IP).我要求为端口映射ip/9999port.

./stunclient --mode full --protocol udp --localport 9999 stun.server.ip
Run Code Online (Sandbox Code Playgroud)

Stun服务器返回IP和端口.我做了什么,然后,打开一个UDP在我的本地系统服务器(使用Java),并开始在监听9999端口和发送UDP的消息other machine (which has public IP),以mapped IP/port通过STUN服务器返回.但我无法收到任何数据.您可以假设我的服务器/客户端代码(用java编写)在本地网络中正常工作.

流:

My machine ->>>>>stun request for 9999 port and my ip ------> stun server
My machine <<<<<<<<<<<<<<<<<<mapped ip/port <<<<<<<<<<<<<<<  stun server
My machine : Run JAVA udp server socket in 9999 port

My machine  <<<<<<<<<<<<<<<<<<<UDP …
Run Code Online (Sandbox Code Playgroud)

stun

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

NotificationChannel总是在Android 8.0中发出声音

我升级target build version27需要实施notification channel.我正在启动一个前景service,它会在启动时显示通知.通过通知渠道,它按预期工作,但它总是如此make sound.更改通知priority没有任何效果.

if(Build.VERSION.SDK_INT >= 26) {
    NotificationChannel notificationChannel = new NotificationChannel(CHANNEL_ID,
            CHANNEL_NAME, NotificationManager.IMPORTANCE_LOW);
    mNotificationManager.createNotificationChannel(notificationChannel);
    notification = new Notification.Builder(this,CHANNEL_ID)
            .setContentTitle("My App")
            .setContentText(status)
            .setSmallIcon(R.drawable.ic_stat_notify)
            .setContentIntent(pendingIntent)
            .build();
}
Run Code Online (Sandbox Code Playgroud)

我已经检查了IMPORTANCE_MIN,IMPORTANCE_DEFAULT而且IMPORTANCE_LOW都在发声

android notification-channel

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