这是我的代码,用于将值从活动类传递给我的服务类.
Intent i = new Intent(this, MyAlarmService.class);
i.putExtra("rowId", rowId);
startactivity(i);
Run Code Online (Sandbox Code Playgroud)
我怎样才能在我的服务类中获得rowId?请帮我
我按下按钮时尝试启动一个新活动,但没有任何反应,我没有错误.这是我的代码:
主要活动
public class CSLearn_Python_AppActivity extends Activity {
String tag = "Events";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
//get content from main.xml
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button login = (Button) findViewById(R.id.loginBtn);
login.setOnClickListener(new OnClickListener(){
public void onClick(View v){
// Intent intent = new Intent("com.Main.Verification");
// startActivity(intent);
Intent myIntent = new Intent(getBaseContext(), Verification.class);
startActivity(myIntent);
}
});
}
Run Code Online (Sandbox Code Playgroud)
新的活动
import android.app.Activity;
import android.os.Bundle;
public class Verification extends Activity{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.verification); …Run Code Online (Sandbox Code Playgroud) 我将值传递给另一个活动,但始终为null值
public class SatelliteDirectActivity extends Activity {
private Intent intent;
private Bundle b;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
intent = new Intent(SatelliteDirectActivity.this,ClsMainActivitySatelliteDirect.class);
b = new Bundle();
setContentView(R.layout.initial_splash_screen);
boolean bCheckInternetConnectivity = checkInternetConnection();
if(!bCheckInternetConnectivity)
{
Toast.makeText(this, "Please ensure that you have a internet connectivity", Toast.LENGTH_SHORT);
finish();
}
else
{
new GetCountryInformation().execute();
}
startActivity(intent);
finish();
}
private boolean checkInternetConnection() {
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
// test for connection
if (cm.getActiveNetworkInfo() != …Run Code Online (Sandbox Code Playgroud) 我使用显式Intent将一个活动转到另一个活动,并在清单文件中声明它.
<activity
android:name=".Activity2"
android:label="Activity 2">
<intent-filter
action android:name="com.tr.ACTIVITY2"
category android:name=”android.intent.category.DEFAULT">
</intent-filter>
</activity>
Run Code Online (Sandbox Code Playgroud)
它工作正常,但有一本书intent-filter用于此,我很困惑当我们使用意图过滤器.
好吧..当我将手机插入计算机时,它启动应用程序,睡眠()完成后,它会崩溃并显示底部显示的错误.我认为你需要的所有代码都显示在引文中.
真的很困惑我为什么会遇到这个问题.我的mainActivity.java文件看起来像这样:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Thread timer = new Thread(){
public void run(){
try{
sleep(1000);
} catch (InterruptedException e){
e.printStackTrace();
}finally{
Intent intent = new Intent("com.worcestershire.android.Pagetwo", null);
startActivity(intent);
}
}
};
timer.start();}
Run Code Online (Sandbox Code Playgroud)
第2页看起来像这样:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@raw/logo"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:text="This is Activity 2" />
<Button android:text="Previous"
android:id="@+id/Button02"
android:layout_width="250px"
android:textSize="18px"
android:layout_height="55px">
</Button>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我的清单看起来像这样:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.worcestershire.android"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="7" />
<application
android:icon="@drawable/maps_launcher"
android:label="@string/app_name" …Run Code Online (Sandbox Code Playgroud) 抱歉愚蠢的问题,java和Android对我来说都是新手;)
我的问题:我无法在一个非常简单的应用程序中切换两个活动.我尝试过类似主题中描述的解决方案,但它没有用.
所以这是我的第一个活动(我没有粘贴导入):
public class OneActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void OnStart(){
Button Btn = (Button)findViewById(R.id.btnNext);
Btn.setOnClickListener(new OnClickListener() {
public void onClick(View Button) {
Intent myIntent = new Intent(OneActivity.this, UserInput.class);
OneActivity.this.startActivity(myIntent);
}
});
}
Run Code Online (Sandbox Code Playgroud)
}
第二个Activity非常简单 - 它只是加载一个名为userinput.xml的布局:
public class UserInput extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.userinput);
Run Code Online (Sandbox Code Playgroud)
} …
我使用Intent从主要活动开始一个活动:
Intent i = new Intent(getApplicationContext(), InfoChiamata.class);
i.putExtra("codice_cliente", codice_cliente[tv_clicked_id]);
i.putExtra("descrizione_chiamata", descrizione_chiamata[tv_clicked_id]);
startActivity(i);
Run Code Online (Sandbox Code Playgroud)
如何编辑从Intent开始的活动中的主要活动ui?我怎么知道我什么时候从第二个活动回到主要活动?我试图覆盖onResume和onStart方法,但应用程序甚至没有启动.我试图在调用应用程序崩溃时覆盖onRestart方法.
@Override
protected void onRestart() {
if(call_back == 1)
Toast.makeText(getApplicationContext(), "asd", Toast.LENGTH_LONG).show();
}
Run Code Online (Sandbox Code Playgroud)
启动时,call_back变量从辅助活动设置为1.
谢谢,马蒂亚
我试图使用此代码以编程方式启动日历同步
Bundle bundle = new Bundle();
bundle.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
bundle.putBoolean(ContentResolver.SYNC_EXTRAS_FORCE, true);
bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
bundle.putBoolean(ContentResolver.SYNC_EXTRAS_IGNORE_SETTINGS, true);
ContentResolver.requestSync(accounts[0], "com.android.calendar", bundle);
Run Code Online (Sandbox Code Playgroud)
我想要一种方式,所以我可以知道同步完成,所以我可以从日历中读取数据,我尝试这样做
while (ContentResolver.isSyncActive(accounts[0], "com.android.calendar")) {
System.out.println("looping: " + i);
}
readLocalCalendar();
readLocalEvents();
Run Code Online (Sandbox Code Playgroud)
但系统在同步结束前退出循环,我仍然可以在状态栏看到同步标志,所以任何帮助,所以我可以在同步完成后阅读日历事件?
谢谢
android android-widget android-emulator android-intent android-layout
当我点击星星时,我正在调整小数值,如1.0,1.5,2.0,2.5等等
如何在自定义评级栏中获得整数评级?
可能吗?
ratingbar.setOnRatingBarChangeListener(new OnRatingBarChangeListener()
{
public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser)
{
Toast.makeText(Rating.this, "New Rating: " + rating, Toast.LENGTH_SHORT).show();
}});
}
Run Code Online (Sandbox Code Playgroud) 在我的应用程序onCreate我检查一些条件,然后我开始这样的活动:
Intent startIntent = new Intent(getApplicationContext(), EnableLocationProviderActivity.class);
startIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplicationContext().startActivity(startIntent);
Run Code Online (Sandbox Code Playgroud)
从该Activity开始,我启动一个IntentService,为传感器注册一些监听器,它以STICKY开头,意味着它应该被显式停止.IntentService监视传感器.
我的问题是,当我回到第一个Activity时,传感器不再感应了(我将一个Log.v放在onSensorChanged中(开始显示数据,然后停止).
如果我没有明确地停止它,为什么它会停止?此外,我看到有时会调用IntentService的OnDestroy,但是,如果它是STICKY并且我没有调用stopself()并且没有以任何其他方式停止,那么如何调用它?
谢谢!吉列尔莫.
编辑
这是IntentService的代码(它应该一直在运行,尽管手机进入睡眠状态或按下主页按钮(我知道电池和其他一切,用户将被警告这个并且会有机会)在他想要时关闭应用程序.
从MainActivity调用该服务,如下所示:
Intent startIntent = new Intent(GdpTesisApplication.getInstance().getApplicationContext(), SensingService.class);
startService(startIntent);
Run Code Online (Sandbox Code Playgroud)
服务代码是这样的:
public class SensingService extends IntentService implements SensorEventListener {
private float[] mAccelerationValues;
private SensorManager mSensorManager = null;
String sensorType = "";
public SensingService(String name) {
super(name);
setIntentRedelivery(true);
}
public SensingService() {
super("SensingService");
setIntentRedelivery(true);
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.v(ApplicationName,"SensingService.onStartCommand");
super.onStartCommand(intent, flags, startId); // If this is not written then onHandleIntent is …Run Code Online (Sandbox Code Playgroud)