我正在尝试通过 Intent 发送内容(我认为这是我错误的原因)并且我不断收到ActivityNotFoundException
. 这是向Tab1.class
(称为温度的字符串)发送数据的类
我在堆栈上发现了类似的问题,有人写道,问题是由在活动完成其生命周期方法之前实例化意图引起的,但我不确定这是否是一个问题,我应该怎么做才能解决它
public class ChooseLayout extends AppCompatActivity implements View.OnClickListener {
EditText editText;
Button button;
Weather weather;
Parser parser = new Parser();
SharedPreferences sharedPreferences;
String temperature, preassure,WindSpeed,WindDirection,Humidity,ViewDescription;
boolean isChecked = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.choose_layout);
editText = (EditText) findViewById(R.id.editText);
button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (!isOnline()) {
Toast.makeText(getApplicationContext(), "Cannot connect to network, data will be restore from file with last downloaded data...", Toast.LENGTH_LONG).show();
} else {
Thread t = new Thread(new Runnable() {
@Override
public void run() {
try {
weather = parser.getWeatherForLocation(editText.getText() + "");
runOnUiThread(new Runnable() {
@Override
public void run() {
editText.setText(weather.getCity() + ", " + weather.getCountry());
temperature = weather.getTemperature();
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
});
t.start();
}
Intent intent = new Intent(getApplicationContext(),Tab1.class);
intent.putExtra("temperature", temperature);
startActivity(intent);
}
});
sharedPreferences = getSharedPreferences("file_name", MODE_PRIVATE);
}
我已经在 AndroidManifest.xml 中声明了这个活动:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.chirag.slidingtabsusingviewpager">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ChooseLayout"></activity>
</application>
</manifest>