我有一个用按钮等登录的活动。在后台,我想使用带有一些图像的全屏-ViewPager,它为用户提供有关这些功能的一些信息等。
如果我的manifest.xml看起来像这样,我只看到我的按钮,徽标等,没有背景图片:
<activity
android:name="com.lo.android.activity.LoginActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
如果我将其更改为以下课程,我会看到背景图片,但没有登录按钮等。 如何在应用程序启动时运行多个类,包括LoginActivity和PageIndicatorActivity?
<activity
android:name="com.lo.android.viewpager.PageIndicatorActivity">
LoginActivity:
package com.lo.android.activity;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.StrictMode;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.lo.android.R;
import com.lo.android.main.Main;
import com.lo.android.service.UserTokenService;
public class LoginActivity extends Activity {
private Button loginButton;
private Button registerButton;
private EditText emailInput;
private EditText passwordInput;
private UserTokenService userTokenService;
private Runnable userTokenServiceCallback;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
// TODO Workaround, use Async solution
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
// End of workaround
emailInput = (EditText) this.findViewById(R.id.email);
passwordInput = (EditText) this.findViewById(R.id.password);
loginButton = (Button) this.findViewById(R.id.loginButton);
loginButton.setOnClickListener(new LoginButtonClickListener());
registerButton = (Button) this.findViewById(R.id.registerButton);
registerButton.setOnClickListener(new RegisterButtonClickListener());
emailInput.setText("marco.mueller@haufe-lexware.com");
userTokenServiceCallback = new Runnable() {
public void run() {
JSONObject json = userTokenService.getResponse();
try {
UserTokenService.userToken = json.getString("SaUser");
Toast.makeText(getApplicationContext(), "Login erfolgreich!", Toast.LENGTH_SHORT).show();
goToMain();
} catch (JSONException e) {
Toast.makeText(getApplicationContext(), "Fehler: " + json.toString() + "\n" + e.toString(), Toast.LENGTH_LONG).show();
}
}
};
}
private void goToMain() {
Intent in = new Intent(LoginActivity.this,Main.class);startActivity(in);
}
private class LoginButtonClickListener implements OnClickListener {
public void onClick(View v) {
String email = emailInput.getText().toString();
String password = passwordInput.getText().toString();
userTokenService = new UserTokenService(getApplicationContext(), userTokenServiceCallback);
userTokenService.call(email, password);
}
}
private class RegisterButtonClickListener implements OnClickListener {
@Override
public void onClick(View arg0) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri
.parse("https://www.lo.de/lp/registration/?cid=232"));
startActivity(browserIntent);
}
}
}
PageIndicatorActivity:
package com.lo.android.viewpager;
import com.lo.android.R;
import com.lo.android.activity.LoginActivity;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.view.Menu;
import android.view.View;
public class PageIndicatorActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
ViewPagerAdapter adapter = new ViewPagerAdapter(this, imageArra);
ViewPager myPager = (ViewPager) findViewById(R.id.viewpager);
myPager.setAdapter(adapter);
myPager.setCurrentItem(0);
}
public void login(View v) {
Intent in = new Intent(PageIndicatorActivity.this, LoginActivity.class);
startActivity(in);
}
private int imageArra[] = { R.drawable.antartica1, R.drawable.antartica2,
R.drawable.antartica3, R.drawable.antartica4,
R.drawable.antartica5, R.drawable.antartica6,
R.drawable.antartica7, R.drawable.antartica8 };
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_login, menu);
return true;
}
}
答案 0 :(得分:1)
使用startActivity(Intent)
从第一个活动开始第二个活动。