I'm doing a basic activity of moving from one page to another. Everything was going perfect until I get two pages deep into the app. I used the same exact code for each page class, put the activities in the manifest and made sure all words were spelled correctly, etc., but the intent doesn't do anything when I try to go three pages deep. There are no error messages in the log at all. When I click on a button on the third page, it just turns blue but doesn't move to the next page like the previous pages. Here's my code:
from page 1 to 3:
Page1:
public class MainActivity extends ActionBarActivity {
Button button;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
addListenerOnButton(); }
public void addListenerOnButton() {
final Context context = this;
button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
Intent intent = new Intent(context, MainMenu.class);
startActivity(intent);
}
});
}
}
Page 2: has more buttons...
public class MainMenu extends ActionBarActivity {
Button button;
Button button2;
Button button3;
Button button4;
Button button5;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_menu);
addListenerOnButton();
}
public void addListenerOnButton() {
final Context context = this;
button = (Button) findViewById(R.id.button1);
button2 = (Button) findViewById(R.id.button2);
button3 = (Button) findViewById(R.id.button3);
button4 = (Button) findViewById(R.id.button4);
button5 = (Button) findViewById(R.id.button5);
button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
Intent intent = new Intent(context, OneMain.class);
startActivity(intent);
}
});
button2.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
Intent intent = new Intent(context, TwoMain.class);
startActivity(intent);
}
});
button3.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
Intent intent = new Intent(context, ThreeMain.class);
startActivity(intent);
}
});
button4.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
Intent intent = new Intent(context, FourMain.class);
startActivity(intent);
}
});
button5.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
Intent intent = new Intent(context, FiveMain.class);
startActivity(intent);
}
});
}
}
Page 3:
public class OneMain extends ActionBarActivity {
Button button;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.one_main);
}
public void addListenerOnButton() {
final Context context = this;
button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
Intent intent = new Intent(context, Alphabet.class);
startActivity(intent);
}
});
}
}
I also made sure I put in all the imports. Someone help. I'm stuck :(.
Here is the manifest xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.juwar74.alarabic"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity android:name=".MainActivity"
android:label="#string/app_name"
android:launchMode="singleTop"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:label="#string/app_name"
android:name=".MainMenu" >
</activity>
<activity
android:label="#string/app_name"
android:name=".OneMain" >
</activity>
<activity
android:label="#string/app_name"
android:name=".TwoMain" >
</activity>
<activity
android:label="#string/app_name"
android:name=".ThreeMain" >
</activity>
<activity
android:label="#string/app_name"
android:name=".FourMain" >
</activity>
<activity
android:label="#string/app_name"
android:name=".FiveMain" >
</activity>
<activity
android:label="#string/app_name"
android:name=".OneVoc" >
</activity>
</application>
</manifest>
And here is the code for the Alphabet.class
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
public class Alphabet extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.alphabet);
}
}
in page3 you never called addListenerOnButton() .
public class OneMain extends ActionBarActivity {
Button button;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.one_main);
// HERE you missed addListenerOnButton();
}
<activity
android:name=".Alphabet " >
</activity>
You missed this in the manifest.xml
First call addListenerOnButton() in OneMain.java after setContentView.
Then check manifest.
Alphabet.class is not registered in manifest.
<activity
android:label="#string/app_name"
android:name=".Alphabet" >
</activity>
After adding it, make sure you are rendering correct xml in Alphabet.java
Related
What i'm trying to do is this:
Make an alarm app, when the alarmmanager activates, switch to a new activity and open the app (The activity where you can stop the alarm)
What happens now with my code is this:
Alarmmanager goes off, it switches to the new activity but the app does not open. You have to open in manually to see the stop alarm screen. How do i do this?
Mainactivity.java
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final TimePicker klok = findViewById(R.id.timePicker1);
klok.setIs24HourView(true);
final Button getTimeBtn = findViewById(R.id.getTimeBtn);
final TextView showText = findViewById(R.id.showText);
Intent intent = new Intent(this, AlarmActivation.class);
final PendingIntent pendingIntent = PendingIntent.getBroadcast(this.getApplicationContext(), 234324243, intent, 0);
final AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
getTimeBtn.setOnClickListener(new View.OnClickListener() {
#RequiresApi(api = Build.VERSION_CODES.M)
#Override
public void onClick(View view) {
int uur = klok.getHour();
int minuut = klok.getMinute();
Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR_OF_DAY, uur);
cal.set(Calendar.MINUTE, minuut);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
Toast.makeText(getApplication().getApplicationContext(), "Alarm gaat om " + uur + ":" + minuut,Toast.LENGTH_LONG).show();
alarmManager.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), pendingIntent);
showText.setText(Integer.toString(uur) + ':' + Integer.toString(minuut));
}
});
}
}
AlarmActivation.java
public class AlarmActivation extends BroadcastReceiver {
MediaPlayer mp;
#Override
public void onReceive(Context context, Intent intent) {
Log.d("alarmact", "voor de service");
Intent alarmIntent = new Intent(context, MainActivity2.class);
alarmIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(alarmIntent);
}
}
MainActivity2.java
public class MainActivity2 extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN |
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON,
WindowManager.LayoutParams.FLAG_FULLSCREEN |
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.wekkerapp">
<uses-permission android:name="android.permission.WAKE_LOCK" />
<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=".MainActivity2"
android:label="#string/title_activity_main2"
android:theme="#style/AppTheme.NoActionBar"></activity>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".AlarmActivation"></receiver>
<service
android:name=".WekkerService"
android:enabled="true"/>
</application>
</manifest>
Hope someone can help me a little with this
How about make BroadcastReceiver in your MainActivity2 ?
like this.
public class MainActivity2 extends AppCompatActivity {
public static final String BROAD_TAG = "braodTag";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN |
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON,
WindowManager.LayoutParams.FLAG_FULLSCREEN |
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
LocalBroadcastManager.getInstance(this).registerReceiver(receiver, new IntentFilter(BROAD_TAG));
}
public BroadcastReceiver receiver = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
if (intent != null) {
if (isRunningActivity) {
//get Data from intent if you need
}
}
}
};
}
and when you send Data, (AlarmActivation.java)
public class AlarmActivation extends BroadcastReceiver {
MediaPlayer mp;
#Override
public void onReceive(Context context, Intent intent) {
Log.d("alarmact", "voor de service");
Intent braodintent = new Intent(MainActivity2.BROAD_TAG);
LocalBroadcastManager.getInstance(this).sendBroadcast(braodintent);
}
}
I keep getting this build error 'class' or 'interface' expected. Everything I'm finding on SO is saying that my Java class is missing (or has an extra) a "}" I'm getting this error in my AndroidManifest.xml for all my Java activities. Here is the Java code:
public class MainActivity extends AppCompatActivity {
protected static final String TAG = "com.example.grey";
EditText SendValue;
Button SendEditTextValue;
Intent intent;
#RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar mToolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(mToolbar);
Log.d(TAG, "onCreate started from Main Activity");
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater mMenuInflater = getMenuInflater();
mMenuInflater.inflate(R.menu.my_menu, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
if(item.getItemId() == R.id.action_setting){
Toast.makeText(MainActivity.this,
"Settings Clicked",
Toast.LENGTH_SHORT).show();
}
if(item.getItemId() == R.id.about_us){
Intent intent = new Intent(this, AboutActivity.class);
startActivity(intent);
}
return super.onOptionsItemSelected(item);
}
public void sendButton(View view){
SendEditTextValue = (Button) findViewById(R.id.button1);
SendValue = (EditText) findViewById(R.id.editText1);
SendEditTextValue.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
intent = new Intent(getApplicationContext(), TextBoxMsgSend.class);
intent.putExtra("EdiTtEXTvALUE", SendValue.getText().toString());
startActivity(intent);
}
});
}
public void movieButton(View view){
Intent intent = new Intent(this, ShowMovies.class);
startActivity(intent);
}
public void button7(View view){
CharSequence text = "Two";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(this, text, duration);
toast.show();
}
public void button8(View view){
CharSequence text = "Three";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(this, text, duration);
toast.show();
}
public void button9(View view){
CharSequence text = "Four";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(this, text, duration);
toast.show();
}
#Override
protected void onStart() {
super.onStart();
Log.d(TAG, "onStart started from Main Activity");
}
#Override
protected void onPause() {
super.onPause();
Log.d(TAG, "onPause started from Main Activity");
}
#Override
protected void onStop() {
super.onStop();
Log.d(TAG, "onStop started from Main Activity");
}
#Override
protected void onDestroy() {
super.onDestroy();
Log.d(TAG, "onDestroy started from Main Activity");
}
#Override
protected void onRestart() {
super.onRestart();
Log.d(TAG, "onRestart started from Main Activity");
}
}
And here is the AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.grey">
<uses-permission android:name="android.permission.INTERNET" />
<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/Theme.AppCompat.Light.NoActionBar">
<!-- The main/home activity (it has no parent activity) -->
<activity android:name="MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- A child of the main activity -->
<activity
android:name=".TextBoxMsgSend"
android:parentActivityName=".MainActivity" />
<activity
android:name=".ShowMovies"
android:parentActivityName=".MainActivity" />
<activity
android:name=".RecyclerAdapter"
android:parentActivityName=".MainActivity" />
<activity
android:name=".MovieDetails"
android:parentActivityName=".ShowMovies" />
<activity
android:name=".AboutActivity"
android:parentActivityName=".MainActivity">
<!-- Parent activity meta-data to support 4.0 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.grey.MainActivity" />
</activity>
</application>
</manifest>
I keep getting build errors and am not able to do any commits. It was working fine the other day so I'm not really sure what changed. I can post my other activities if needed.
public class MovieDetails extends AppCompatActivity{
private static final String TAG = "MovieDetailsActivity";
#Override
protected void onCreate(#Nullable Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_movie_details);
Log.d(TAG, "Started program.");
getGalleryIntent();
}
private void getGalleryIntent(){
if(getIntent().hasExtra("image_url") && getIntent().hasExtra("image_name")){
Log.d(TAG,"Found intents.");
String imageURL = getIntent().getStringExtra("image_url");
String imageName = getIntent().getStringExtra("image_name");
String imageYear = getIntent().getStringExtra("image_year");
String imageDirector = getIntent().getStringExtra("image_director");
String imageDescription = getIntent().getStringExtra("image_description");
setImage(imageURL, imageName, imageYear, imageDirector, imageDescription);
}
}
private void setImage(String imageURL, String imageName, String imageYear, String imageDirector, String imageDescription){
TextView name = findViewById(R.id.title);
name.setText(imageName);
TextView year = findViewById(R.id.year);
year.setText(imageYear);
TextView director = findViewById(R.id.director);
director.setText(imageDirector);
TextView description = findViewById(R.id.description);
description.setText(imageDescription);
ImageView image = findViewById(R.id.image);
Glide.with(this).asBitmap().load(imageURL).into(image);
}
}
Try a period before MainActivity where it's declared in the manifest.
I'm beginner in Android Studio. My app allows me to add users(fn,ln,adrs,Uri::ImageUri) and list them and view their info.
I want to be able to display one user's info when clicking on my listview.
The problem is that i only get a blank space instead of my desired imageview.
My main activity :
public class MainActivity extends AppCompatActivity {
public static ArrayList <User> users =new ArrayList <User>();
public static User userSelected;
public static ListView mListView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(activity_main);
mListView = (ListView) findViewById(R.id.List);
}
public void InputInfo(View view) {
Intent AddEmployee = new Intent(this, NewEmployeeInfo.class);
startActivityForResult(AddEmployee,0);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(0, resultCode, data);
finaltest =NewEmployeeInfo .targetUri ;
UserAdapter useradapter;
useradapter = new UserAdapter (MainActivity .this, android.R.layout.simple_list_item_1, users ) ;
mListView.setAdapter(useradapter );
mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> adapter, View view, int position, long arg) {
Intent appInfo = new Intent(MainActivity.this, DisplayInfo.class);
User temp= users.get(position );
userSelected =new User(temp.first_name ,temp.last_name,temp.adr,temp.url );
startActivity(appInfo);
}
});
}
}
My second one (where the user inputs the info :
public class NewEmployeeInfo extends AppCompatActivity {
public ImageView imageview;
public ImageView targetImage;
public User u;
public static Bitmap photo;
public static Uri targetUri;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_new_employee_info);
}
public void takePhoto(View view) {
Intent takePicture = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(takePicture, 0);
}
public void pickphoto(View view) {
Intent pickPhoto = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(pickPhoto, 1);
}
protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) {
super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
imageview = (ImageView) this.findViewById(imageView);
resultphoto(requestCode, resultCode, imageReturnedIntent);
}
public void Save(View view) {
Intent SaveDataIntent = new Intent(this, MainActivity.class);
EditText FN = (EditText) findViewById(R.id.editText);
EditText LN = (EditText) findViewById(R.id.editText5);
EditText ADDRESS = (EditText) findViewById(R.id.editText6);
String firstname = FN.getText().toString();
String lastname = LN.getText().toString();
String address = ADDRESS.getText().toString();
if (firstname.length() == 0 || lastname.length() == 0 || address.length() == 0) {
Toast.makeText(this, "No Emty Fields!!",
Toast.LENGTH_LONG).show();
return;
}
u = new User(firstname, lastname, address, targetUri);
users.add(u);
setResult(RESULT_OK, SaveDataIntent);
finish();
}
private void resultphoto(int requestCode, int resultCode, Intent imageReturnedIntent) {
switch (requestCode) {
case 0:
if (resultCode == RESULT_OK) {
targetUri = imageReturnedIntent.getData();
imageview.setImageURI(targetUri);
imageReturnedIntent.getExtras().get("data");
}
break;
case 1:
if (resultCode == RESULT_OK) {
targetUri = imageReturnedIntent.getData();
targetImage = (ImageView) findViewById(imageView);
try {
photo = BitmapFactory.decodeStream(getContentResolver().openInputStream(targetUri));
targetImage.setImageBitmap(photo);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
break;
}
}
}
the third and final one(Where the info should be displayed)
public class DisplayInfo extends AppCompatActivity {
public ImageView imageView;
public Bitmap image;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display_info);
TextView fn = (TextView) findViewById(R.id.firstname);
TextView ln = (TextView) findViewById(R.id.lastname);
TextView adr = (TextView) findViewById(R.id.address);
imageView = (ImageView) findViewById(R.id.imageView2);
fn.setText(MainActivity.userSelected.first_name);
ln.setText(MainActivity.userSelected.last_name);
adr.setText(MainActivity.userSelected.adr);
imageView.setImageURI(MainActivity.userSelected.url ) ;
This error keep showing up
E/DatabaseUtils: Writing exception to parcel
java.lang.SecurityException: Permission Denial: reading com.android.providers.media.MediaProvider uri content://media/external/images/media/810 from pid=12644, uid=10280 requires android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission()
Though I included these permissions in my manifest file:
<uses-permission
android:name="android.permission.READ_EXTERNAL_STORAGE"
/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
Ask runTime permissions
tutorial
My problem was in the Manifest file;
It was
<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=".NewEmployeeInfo">
android:parentActivityName=".MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
<activity android:name=".DisplayInfo" />
<activity android:name=".UserAdapterActivity"></activity>
<uses-permission
android:name="android.permission.READ_EXTERNAL_STORAGE"
/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
</application>
I misplaced my permissions. It should've been like this
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mobilonia.employeesapp">
<uses-permission
android:name="android.permission.READ_EXTERNAL_STORAGE"
/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<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=".NewEmployeeInfo">
android:parentActivityName=".MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
<activity android:name=".DisplayInfo" />
<activity android:name=".UserAdapterActivity"></activity>
</application>
</manifest>
This is my first question and i already searched for an answer, but i couldn't find one.
My App starts with an SplashScreen Video and after the Video is done the Activity tries to start my MainActivity wich extends FragmentActivity. But the App crashes with following Log:
05-17 11:32:56.554: W/Binder(476): Caught a RuntimeException from the binder stub implementation.
05-17 11:32:56.554: W/Binder(476): java.lang.NullPointerException
05-17 11:32:56.554: W/Binder(476): at android.inputmethodservice.IInputMethodWrapper.setSessionEnabled(IInputMethodWrapper.java:280)
05-17 11:32:56.554: W/Binder(476): at com.android.internal.view.IInputMethod$Stub.onTransact(IInputMethod.java:129)
05-17 11:32:56.554: W/Binder(476): at android.os.Binder.execTransact(Binder.java:404)
05-17 11:32:56.554: W/Binder(476): at dalvik.system.NativeStart.run(Native Method)
05-17 11:32:56.554: W/InputMethodManagerService(360): Got RemoteException sending setActive(false) notification to pid 1075 uid 10052
05-17 11:32:56.574: W/IInputConnectionWrapper(514): showStatusIcon on inactive InputConnection
Here is What my SplashScreen class looks like:
public class SplashScreen extends Activity {
// Splash screen timer
private static int SPLASH_TIME_OUT = 6000;
public void Skip(View v) {
SPLASH_TIME_OUT = 0;
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
VideoView mVideoView = (VideoView)findViewById(R.id.intro);
String uriPath = "android.resource://de.ebs_hannover.sean.elsaapp/"+R.raw.intro_vid;
Uri uri = Uri.parse(uriPath);
mVideoView.setVideoURI(uri);
mVideoView.requestFocus();
mVideoView.start();
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
// This method will be executed once the timer is over
// Start your app main activity
Intent i = new Intent(SplashScreen.this, MainActivity.class);
startActivity(i);
// close this activity
finish();
}
}, SPLASH_TIME_OUT);
}
}
And This is my MainActivity:
public class MainActivity extends FragmentActivity{
ViewPager viewPager=null;
TextView cPosTxt =null;
#Override
protected void onCreate(Bundle arg0) {
super.onCreate(arg0);
setContentView(R.layout.activity_main);
cPosTxt = (TextView) findViewById(R.id.cPosTxt);
viewPager= (ViewPager) findViewById(R.id.pager);
FragmentManager fragmentManager=getSupportFragmentManager();
viewPager.setAdapter(new MyAdapter(fragmentManager));
viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
#Override
public void onPageSelected(int arg0) {
if(arg0==0) {
cPosTxt.setText(R.string.menue);
}
if (arg0==1) {
cPosTxt.setText(R.string.btn_jubi);
}
if (arg0==2) {
cPosTxt.setText(R.string.btn_info);
}
if (arg0==3) {
cPosTxt.setText(R.string.btn_story);
}
if (arg0==4) {
cPosTxt.setText(R.string.btn_events);
}
if (arg0==5) {
cPosTxt.setText(R.string.btn_current);
}
}
#Override
public void onPageScrollStateChanged(int arg0) {
// TODO Auto-generated method stub
}
#Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
// TODO Auto-generated method stub
}
});
}
public void StroemClick(View v) {
viewPager.setCurrentItem(0, true);
}
public void JubiClick(View v) {
viewPager.setCurrentItem(1, true);
}
public void InfoClick(View v) {
viewPager.setCurrentItem(2, true);
}
public void StoryClick(View v) {
viewPager.setCurrentItem(3, true);
}
public void EventsClick(View v) {
viewPager.setCurrentItem(4, true);
}
public void CurrentClick(View v) {
viewPager.setCurrentItem(5, true);
}
}
class MyAdapter extends FragmentStatePagerAdapter {
public MyAdapter(FragmentManager fm) {
super(fm);
}
#Override
public Fragment getItem(int arg0) {
Fragment fragment=null;
if(arg0==0){
fragment=new MenuFragment();
}
if(arg0==1) {
fragment=new JubiFragment();
}
if(arg0==2) {
fragment=new InfoFragment();
}
if(arg0==3){
fragment=new StoryFragment();
}
if(arg0==4){
fragment=new EventsFragment();
}
if(arg0==5){
fragment=new CurrentFragment();
}
return fragment;
}
#Override
public int getCount() {
return 6;
}
}
And just in case (because i have the suggestion that this might be the problem) here is my Manifest aswell:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.ebs_hannover.sean.elsaapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen" >
<activity
android:name="de.ebs_hannover.sean.elsaapp.SplashScreen"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
What am i doing wrong? Without the SplashScreen at the begining it works fine... So When i set my MainActivity to the Launcher Activity in the Manifest... Thanks for any help :)
Try to add the MainActivity Class inside your <application> tag:
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen" >
<activity
android:name="de.ebs_hannover.sean.elsaapp.SplashScreen"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
// ADD ALL ACTIVITIES LIKE THIS:
<activity
android:name="de.ebs_hannover.sean.elsaapp.MainActivity"
android:label="#string/app_name" />
</application>
I am trying to put 2 different layouts in my android application
and that on value in register using shared preferences
this is my code .. it stopped once i click logo
Part of
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SharedPreferences prefs;
//String register;
prefs = PreferenceManager.getDefaultSharedPreferences(this);
register=prefs.getString("register", "no");
if(register.equalsIgnoreCase("no")) {
setContentView(R.layout.main_activity);
}
else
{
setContentView(R.layout.about);
}
}
the LogCat error
FATAL EXCEPTION: main
Process:com,cpcs,irissystem, PID:31749
java.lang.RuntimeExeption : unable to start activity componentInfo
{......MainActivity }:java.lang.NullPointerException
at android.app.ActivityThread.preformLaunchActivity(ActivityThread.java2328)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java2386)
At android.app.ActivityThread.access$900(ActivityThread.java:169)
At android.app.ActivityThread$H.handleMessage(ActivityThread.java:1277)
At android.os.Handler.dispatchMeesage(Handler.java:102)
At android.os.looper.loop(LooperLjava:136)
At android.app.ActivityThread.Main(ActivityThread.java:5476)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$methodAndArgsCaller.run....:1268)
Activity Class
public class MainActivity extends Activity {
public static String register;
private static final int CAMERA_REQUEST = 1888;
public static String IrisCode;
String IrisCode2;
ImageView imageView;
private static Bitmap eyeImage;
EditText passwordText;
public static float perc ;
SharedPreferences prefs;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
prefs = PreferenceManager.getDefaultSharedPreferences(this);
register=prefs.getString("register", "no");
if(register.equalsIgnoreCase("no")) {
setContentView(R.layout.main_activity);
}
else
{
setContentView(R.layout.about);
}
Toast.makeText(MainActivity.this,"befroe: "+ register, Toast.LENGTH_LONG).show();
Button InstructionButton = (Button) findViewById(R.id.inst);
Button enrollButton = (Button) findViewById(R.id.enroll);
Button verifyButton = (Button) findViewById(R.id.ver);
passwordText = (EditText) findViewById(R.id.pass);
if(register.equalsIgnoreCase("no")){
verifyButton.setEnabled(false);
}
enrollButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
//Go to the next page
//if Not registered before go to start to enter data
//else go to setting
Intent i = new Intent();
if(register.equalsIgnoreCase("no")) {
i = new Intent (MainActivity.this,start.class);
startActivity(i);
}
else
{
i = new Intent (MainActivity.this,setting.class);
startActivity(i);
}
}
});
InstructionButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
//Go to the instruction page
Intent i = new Intent (MainActivity.this,instruction.class);
startActivity(i);
}
});
verifyButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
if("0000".equals(passwordText.getText().toString())){
String same="aothorizes acess";
Toast.makeText(MainActivity.this, same, Toast.LENGTH_LONG).show();
Intent i = new Intent (MainActivity.this,setting.class);
startActivity(i);
}
}
});
}
Manifest
<application
android:allowBackup="true"
android:icon="#drawable/logo"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.cpcs.irissystem.MainActivity"
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=".start" />
<activity
android:name=".setting" />
<activity
android:name=".aboutus" />
<activity
android:name=".instruction" />
<activity
android:name=".setting2"/>
<activity
android:name=".ver"/>
</application>
// Try this way,hope this will help you...
SharedPreferences prefs;
String register;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
prefs = PreferenceManager.getDefaultSharedPreferences(this);
register=prefs.getString("register", "no");
if(register.equalsIgnoreCase("no")) {
setContentView(R.layout.activity_main);
}
else
{
setContentView(R.layout.activity_main2);
}
}