无法打开活动,在启动画面后屏幕闪烁

时间:2017-01-27 12:00:30

标签: android android-activity

我是Android编程的新手。我有一个启动画面,之后我试图打开一个活动,但在启动画面后,我的屏幕一直闪烁,活动也没有打开。什么都有。我的代码如下:

Splashscreen.java

 public class splashscreen extends AppCompatActivity 
{

ImageView imageView;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_splashscreen);
    imageView =(ImageView)findViewById(R.id.imageView);
    Animation animation= AnimationUtils.loadAnimation(getApplicationContext(),R.anim.slideinright);
    imageView.setAnimation(animation);

    animation.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {

        }

        @Override
        public void onAnimationEnd(Animation animation) {
            finish();
            startActivity(new Intent(getApplicationContext(),MainActivity.class));

        }

        @Override
        public void onAnimationRepeat(Animation animation) {

        }
    });
}
}

Loginpage.java

import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
 import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.facebook.CallbackManager;
import com.facebook.FacebookCallback;
import com.facebook.FacebookException;
 import com.facebook.FacebookSdk;
import com.facebook.Profile;
import com.facebook.ProfileTracker;
import com.facebook.appevents.AppEventsLogger;
import com.facebook.login.LoginResult;
 import com.facebook.login.widget.LoginButton;
 import com.google.android.gms.tasks.OnCompleteListener;
 import com.google.android.gms.tasks.Task;
 import com.google.firebase.auth.AuthResult;
 import com.google.firebase.auth.FirebaseAuth;

  public class LoginActivity2 extends AppCompatActivity implements       View.OnClickListener {

private Button loginbuttonRegister;
private EditText logineditTextEmail;
private EditText logineditTextPassword;
private TextView textViewLogin;
private ProgressDialog progressDialog;
private FirebaseAuth firebaseAuth;

private LoginButton loginButton;
private CallbackManager callbackManager;
private Profile profile;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login2);
     progressDialog = new ProgressDialog(this);
    firebaseAuth = FirebaseAuth.getInstance();
    if( firebaseAuth.getCurrentUser() != null){

        //display navigation activity
        finish();
        startActivity(new    Intent(getApplicationContext(),MainActivity.class));
    }
    loginbuttonRegister = (Button) findViewById(R.id.loginbuttonRegister);
    logineditTextEmail = (EditText) findViewById(R.id.logineditTextEmail);
    logineditTextPassword = (EditText)   findViewById(R.id.logineditTextPassword);
    textViewLogin =(TextView) findViewById(R.id.textViewLogin);
    loginbuttonRegister.setOnClickListener(new View.OnClickListener(){

        public void onClick(View v) {
            loginbuttonRegister = (Button)          findViewById(R.id.loginbuttonRegister);
            if(v == loginbuttonRegister)
            {
                userLogin();
            }

        }



    });
    textViewLogin.setOnClickListener(this);




    //Initializing Facebook Sdk.
    FacebookSdk.sdkInitialize(getApplicationContext());
    AppEventsLogger.activateApp(this);
    //intialize callback manager
    callbackManager = CallbackManager.Factory.create();
    //initializing facebook login button

    loginButton = (LoginButton) findViewById(R.id.login_button);
    loginButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            // Perform action on click

            loginButton = (LoginButton)findViewById(R.id.login_button);
            loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
                ProfileTracker profileTracker;
                @Override
                public void onSuccess(LoginResult loginResult) {
                    Toast.makeText(LoginActivity2.this,"Succesfully Logged In",Toast.LENGTH_SHORT).show();
                    profile = Profile.getCurrentProfile();
                    //check profile is fetched or not, if not then wait for sometime
                    // to load your profile using profile tracker
                    if(profile == null){
                        profileTracker = new ProfileTracker() {
                            @Override
                            protected void onCurrentProfileChanged(Profile profile, Profile profile1) {
                                if(profile1 != null){
                                    startActivity(new Intent(LoginActivity2.this,MainActivity.class));
                                }
                            }
                        };
                    }else{
                        startActivity(new Intent(LoginActivity2.this,MainActivity.class));
                    }
                }

                @Override
                public void onCancel() {

                }

                @Override
                public void onError(FacebookException e) {

                }
            });
        }
    });





   }

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    callbackManager.onActivityResult(requestCode,resultCode,data);
}





private void userLogin(){
    String email = logineditTextEmail.getText().toString().trim();
    String password = logineditTextPassword.getText().toString().trim();

    if(TextUtils.isEmpty(email)){
        //mail empty

        Toast.makeText(this, "Please enter email!", Toast.LENGTH_SHORT).show();
        return;
    }

    if(TextUtils.isEmpty(password)){
        Toast.makeText(this, "Please enter Password!", Toast.LENGTH_SHORT).show();
        return;
    }
    //if valid then shows progressbar
    progressDialog.setMessage("Loggin in...!");

    progressDialog.show();
    firebaseAuth.createUserWithEmailAndPassword(email,password).addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
        @Override
        public void onComplete(@NonNull Task<AuthResult> task) {
            if(task.isSuccessful())
            {    progressDialog.dismiss();
                //start anvigation activity
                finish();
                startActivity(new Intent(getApplicationContext(),MainActivity.class));
            }

            else {progressDialog.dismiss();
                Toast.makeText(LoginActivity2.this, "Failed to login! Try again.", Toast.LENGTH_SHORT).show();
            }
        }
    });
}
@Override
public void onClick(View view) {

    if(view == textViewLogin)
    {finish();
    startActivity(new Intent(this,Registeruser.class));
    }
  }
}

Loginactivity.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/content_login2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.example.dell.Swing.LoginActivity2"
tools:showIn="@layout/activity_login2"
android:background="@drawable/probeach">

<LinearLayout
    android:id="@+id/registerlayout"
    android:orientation="vertical"
    android:layout_centerVertical="true"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <EditText
        android:layout_margin="10dp"
        android:hint="Enter your E-mail"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="textEmailAddress"
        android:id="@+id/logineditTextEmail"
        />

    <EditText
        android:layout_margin="10dp"
        android:hint="Enter your Password"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="textPassword"
        android:id="@+id/logineditTextPassword" />

    <Button
        android:layout_margin="10dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/loginbuttonRegister"
        android:text="Log In"
        style="@style/Widget.AppCompat.Button.Colored"
        android:background="@android:color/holo_red_dark"
        android:elevation="0dp" />


    <TextView
        android:textAlignment="center"
        android:text="Not Registered? Sign up Here"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/textViewLogin" />
</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:layout_marginBottom="66dp"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:weightSum="1">

    <TextView
        android:id="@+id/orview"
        android:text="Or"
        android:gravity="center"
        android:textAppearance="@style/TextAppearance.AppCompat.Button"
        android:layout_width="match_parent"
        android:layout_weight="0.63"
        android:layout_height="40dp" />

    <com.facebook.login.widget.LoginButton
    android:layout_margin="10dp"
    android:id="@+id/login_button"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_below="@+id/orview"
     />
</LinearLayout>

1 个答案:

答案 0 :(得分:0)

请检查您的背景图片分辨率,

android:background="@drawable/probeach"