在我的应用程序中,我读取保存在手机上的联系人,这可能需要很长时间,然后我将其放在Thread我正在使用的嵌套中Realm,但出现此错误:
Realm access from incorrect thread.
Realm objects can only be accessed on the thread they were created.
Run Code Online (Sandbox Code Playgroud)
我的解决方案不能解决这个问题,例如:
new Handler().post(new Runnable() {
@Override
public void run() {
realm.executeTransaction(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
}
});
}
});
Run Code Online (Sandbox Code Playgroud)
或者
new Handler(getMainLooper()).post(new Runnable() {
@Override
public void run() {
realm.executeTransaction(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
}
});
}
});
Run Code Online (Sandbox Code Playgroud)
在嵌套线程上,
当手机靠近某个位置时,我正试图更新并更新.我都尝试过使用addProximityAlert和requestLocationUpdates
LocationManager lm =(LocationManager) getSystemService(Context.LOCATION_SERVICE);
Location l = lm.getLastKnownLocation("gps");
Intent intent = new Intent("eu.mauriziopz.gps.ProximityAlert");
PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0);
lm.addProximityAlert(12, 12, 100, 1000000, pIntent);
Run Code Online (Sandbox Code Playgroud)
这个从不激发意图(我知道它可以工作,因为我可以手动启动它).我尝试使用一个监听器但它只执行一次.无论我多少次更新gps,它都不会被再次调用
ProximityListener pl = new ProximityListener();
lm. requestLocationUpdates("gps", 2000, 10, pl);
Run Code Online (Sandbox Code Playgroud)
这是活动的代码(在第一种情况下调用)
public class ProximityAlert extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
Log.d("intent", "Hi");
finish();
}
Run Code Online (Sandbox Code Playgroud)
这是听众
public class ProximityListener implements LocationListener {
String DEBUG_TAG = "ProximityListener";
@Override
public void onLocationChanged(Location location) {
// TODO Auto-generated …Run Code Online (Sandbox Code Playgroud) 我Scrollview在一些layouts我是 android 新手下留下空间,请帮助这里是我的代码:
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scrollviewdb"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="15sp"
android:padding="5dp"
android:id="@+id/ghavaed_text"/>
</LinearLayout>
</ScrollView>
Run Code Online (Sandbox Code Playgroud) 从文件中将行作为字符串读取时, string.contains("someexamplestring") 将返回区分大小写的字符串的输出。
如果行中有“someExampleString”,则它不会返回。
如何以不区分大小写的方式识别字符串?
所以我有以下场景:
class NowActivity: AppCompatActivity(), NowScreen, NowDelegate by NowDelegateImpl(){
onCreate(...){
presenter.attachView(this)
}
Run Code Online (Sandbox Code Playgroud)
有什么方法可以将某些NowScreen方法的实现委托给 NowDelegate 以便我可以在演示者内部执行以下操作:
view.callSomeFunc()
Run Code Online (Sandbox Code Playgroud)
其中 callSomeFund() 在NowDelegate.
有没有办法完成这样的事情?问题是我正在使用 MVP,它将视图附加到演示者。但是一些视图实现在几个活动中重复,所以我想将它委托给另一个类。
我收到这个错误我改变了所有几乎setwallpaper设置wallpapermanager和trget sdk和min也设置.仍然没有找到解决方法如何删除清单错误.已经为set_Wallpaper添加了权限.
================================================== ======================
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.androidme"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.SET_WALLPAPER"/>
<uses-permission />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.androidme.Splash"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.androidme.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.example.androidme.MainActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.example.androidme.Menu"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.example.androidme.Menu" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.example.androidme.TextPlay" …Run Code Online (Sandbox Code Playgroud) 我有以下方法,我想展示一个Snackbar.问题是,我没有我的活动view,我不知道如何得到它.在代码中,你会发现Snackbar view是viewInflate_setup,但它不工作.我知道它不起作用,因为这是我的视图,alertdialog而不是我当前的屏幕.我已经尝试了root view但是然后snackbar显示在错误的地方(在这三个android按钮后面).我如何获得我的活动View?
public void confirmPassword(){
final LayoutInflater inflateSetup = getLayoutInflater();
final View viewInflate_setup = inflateSetup.inflate(R.layout.inflate_setup, null);
AlertDialog.Builder alertSetup = new AlertDialog.Builder(this);
alertSetup.setView(viewInflate_setup);
final AlertDialog dialogSetup = alertSetup.create();
dialogSetup.show();
btnConfirmPassowod = (Button)viewInflate_setup.findViewById(R.id.btnConfirm);
btnConfirmPassowod.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
System.out.println("User has clicked the [confirm] button");
dialogSetup.setCancelable(false);
edtPassword3 = (EditText)viewInflate_setup.findViewById(R.id.edtPassword3);
SUpassword3 = edtPassword3.getText().toString();
final ParseUser beforeConfirmPassword = ParseUser.getCurrentUser();
ParseUser.logInInBackground(beforeConfirmPassword.getUsername(), SUpassword3, new LogInCallback() …Run Code Online (Sandbox Code Playgroud) 当我从某个活动更新窗口小部件时,列表远程视图没有更新(我的意思是刷新自己).它出现在应用程序小部件的更新(日志显示)上.但是没有进入列表视图的适配器以使用新数据对其进行充气.
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
final int N = appWidgetIds.length;
for (int i = 0; i < N; i++) {
int appWidgetId = appWidgetIds[i];
Log.e("called", "onupdate");
RemoteViews views = new RemoteViews(context.getPackageName(),
R.layout.widget_lay);
views.setTextViewText(R.id.textView1,
"Floating Text will be displayed here .. Daily Thoughts");
Intent intent = new Intent(context, RemoteServiceEmin.class);
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
views.setRemoteAdapter(R.id.gridview, intent);
// inflating list remote view
Intent intentlist = new Intent(context, ListInflater.class);
intentlist.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
appWidgetId);
intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
views.setRemoteAdapter(R.id.listview, intentlist);
// setting onclick on gridview
Intent itemClickIntent …Run Code Online (Sandbox Code Playgroud) 在我的数据库中,我有一些存储过程.
我想打电话给他们中的一个,根据我从这个程序得到的结果,我将确定天气是否打电话给第二个.
正如你在isUserValid()我使用过的方法中看到的那样$result->free_results()
但仍然在调用我得到的其他程序时: Commands out of sync; you can't run this command now
这是我对db函数的调用:
/**
* Run a new query on the db.
* this will open an close the connection to the db
* @param $query string the query to run
* @param $verifyAccessToken boolean true if user validation is needed before query is executed, false otherwise
* @return bool|mysqli_result the result of the query if any or true or false in a non query …Run Code Online (Sandbox Code Playgroud) 在我的应用程序中,用户选择 1、21、51、101、108 之类的计数,就像他使用按钮或单选按钮选择时一样,媒体播放器必须重复多次。如果他选择 21,媒体播放器应该重复播放音乐 21 次。在我的代码中,如果我在 for 循环中使用 while 循环,它会阻塞 UI,不允许停止或暂停播放,如果我没有使用 while 循环,它只会播放一次。请我需要解决它,任何人都会提前感谢。下面我发布了我的整个代码
public class MainActivity extends Activity implements OnClickListener{
private MediaPlayer mp;
int count;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setVolumeControlStream(AudioManager.STREAM_MUSIC);
findViewById(R.id.button_1).setOnClickListener(this);
findViewById(R.id.button_2).setOnClickListener(this);
findViewById(R.id.button_3).setOnClickListener(this);
findViewById(R.id.button_4).setOnClickListener(this);
findViewById(R.id.button_5).setOnClickListener(this);
findViewById(R.id.pause).setOnClickListener(this);
findViewById(R.id.stop).setOnClickListener(this);
}
public void onClick(View v) {
switch (v.getId()) {
case R.id.button_1:
if (mp!=null) {
mp.release();
}
player(3);
break;
case R.id.button_2:
if (mp!=null) {
mp.release();
}
player(21);
break;
case R.id.button_3:
if (mp!=null) {
mp.release();
}
player(51);
break;
case R.id.button_4:
if …Run Code Online (Sandbox Code Playgroud)