Application restart if i changed the launcher activity in XML manifest - java

I have a funny problem, I have my project act wired, am following some tutorials and copied some codes, but now I figured that I cannot put any of my activities as launcher activity except the main activity , I looked really deep in it and didn't find anything that make it the only activity that fits to be the launcher activity , is it a manifest problem ? or special flag in the main activity ??!!
please take a look at the main activity and the manifest:-
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.rozdoum.socialcomponents">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_INTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_LOGS" />
<uses-permission android:name="android.permission.CAMERA" />
<application
android:name=".Application"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="#string/facebook_app_id" />
<activity
android:name=".main.main.MainActivity"
android:configChanges="orientation|screenSize"
android:theme="#style/AppCompat.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".main.postDetails.PostDetailsActivity"
android:configChanges="orientation|screenSize"
android:label="#string/label_post_detail_activity" />
<activity
android:name=".main.post.createPost.CreatePostActivity"
android:configChanges="orientation|screenSize"
android:label="#string/label_create_post_activity" />
<activity
android:name=".main.imageDetail.ImageDetailActivity"
android:configChanges="orientation|screenSize"
android:label="#string/label_image_detail_activity"
android:theme="#style/AppCompat.Black.NoActionBar" />
<activity
android:name=".main.login.LoginActivity"
android:label="#string/title_activity_login"
android:theme="#style/AppCompat.NoActionBar" />
<activity
android:name=".main.editProfile.createProfile.CreateProfileActivity"
android:configChanges="orientation|screenSize"
android:label="#string/title_activity_create_profile" />
<activity
android:name="com.theartofdev.edmodo.cropper.CropImageActivity"
android:theme="#style/Base.Theme.AppCompat" />
<activity
android:name=".main.profile.ProfileActivity"
android:configChanges="orientation|screenSize"
android:label="#string/title_activity_profile"
android:theme="#style/AppCompat.NoActionBar" />
<activity
android:name=".main.editProfile.EditProfileActivity"
android:configChanges="orientation|screenSize"
android:label="#string/title_activity_edit_profile" />
<activity
android:name=".main.post.editPost.EditPostActivity"
android:configChanges="orientation|screenSize"
android:label="#string/title_activity_edit_post" />
<activity
android:name=".main.usersList.UsersListActivity"
android:configChanges="orientation|screenSize"
android:theme="#style/AppCompat.NoActionBar" />
<activity
android:name=".main.followPosts.FollowingPostsActivity"
android:configChanges="orientation|screenSize"
android:label="#string/title_activity_following_posts"
android:theme="#style/AppCompat.NoActionBar" />
<activity
android:name=".main.search.SearchActivity"
android:configChanges="orientation|screenSize"
android:theme="#style/AppCompat.NoActionBar"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data
android:name="android.app.searchable"
android:resource="#xml/searchable" />
</activity>
<meta-data
android:name="io.fabric.ApiKey"
android:value="84e05e27c9fcba7e1de6a47e355a1aa247264a46" />
<service android:name=".services.MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<service android:name=".services.MyFirebaseInstanceIDService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
</application>
</manifest>
main activity
public class MainActivity extends BaseActivity<MainView, MainPresenter> implements MainView {
private PostsAdapter postsAdapter;
private RecyclerView recyclerView;
private FloatingActionButton floatingActionButton;
private TextView newPostsCounterTextView;
private boolean counterAnimationInProgress = false;
private ProgressBar progressBar;
private SwipeRefreshLayout swipeContainer;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
initContentView();
}
#Override
protected void onResume() {
super.onResume();
presenter.updateNewPostCounter();
}
#NonNull
#Override
public MainPresenter createPresenter() {
if (presenter == null) {
return new MainPresenter(this);
}
return presenter;
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
switch (requestCode) {
case ProfileActivity.CREATE_POST_FROM_PROFILE_REQUEST:
refreshPostList();
break;
case CreatePostActivity.CREATE_NEW_POST_REQUEST:
presenter.onPostCreated();
break;
case PostDetailsActivity.UPDATE_POST_REQUEST:
presenter.onPostUpdated(data);
break;
}
}
}
#Override
public void onBackPressed() {
attemptToExitIfRoot(floatingActionButton);
}
public void refreshPostList() {
postsAdapter.loadFirstPage();
if (postsAdapter.getItemCount() > 0) {
recyclerView.scrollToPosition(0);
}
}
#Override
public void removePost() {
postsAdapter.removeSelectedPost();
}
#Override
public void updatePost() {
postsAdapter.updateSelectedPost();
}
#Override
public void showCounterView(int count) {
AnimationUtils.showViewByScaleAndVisibility(newPostsCounterTextView);
String counterFormat = getResources().getQuantityString(R.plurals.new_posts_counter_format, count, count);
newPostsCounterTextView.setText(String.format(counterFormat, count));
}
private void initContentView() {
if (recyclerView == null) {
progressBar = findViewById(R.id.progressBar);
swipeContainer = findViewById(R.id.swipeContainer);
initFloatingActionButton();
initPostListRecyclerView();
initPostCounter();
}
}
private void initFloatingActionButton() {
floatingActionButton = findViewById(R.id.addNewPostFab);
if (floatingActionButton != null) {
floatingActionButton.setOnClickListener(v -> presenter.onCreatePostClickAction(floatingActionButton));
}
}
private void initPostListRecyclerView() {
recyclerView = findViewById(R.id.recycler_view);
postsAdapter = new PostsAdapter(this, swipeContainer);
postsAdapter.setCallback(new PostsAdapter.Callback() {
#Override
public void onItemClick(final Post post, final View view) {
presenter.onPostClicked(post, view);
}
#Override
public void onListLoadingFinished() {
progressBar.setVisibility(View.GONE);
}
#Override
public void onAuthorClick(String authorId, View view) {
openProfileActivity(authorId, view);
}
#Override
public void onCanceled(String message) {
progressBar.setVisibility(View.GONE);
showToast(message);
}
});
recyclerView.setLayoutManager(new LinearLayoutManager(this));
((SimpleItemAnimator) recyclerView.getItemAnimator()).setSupportsChangeAnimations(false);
recyclerView.setAdapter(postsAdapter);
postsAdapter.loadFirstPage();
}
private void initPostCounter() {
newPostsCounterTextView = findViewById(R.id.newPostsCounterTextView);
newPostsCounterTextView.setOnClickListener(v -> refreshPostList());
presenter.initPostCounter();
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
#Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
hideCounterView();
super.onScrolled(recyclerView, dx, dy);
}
});
}
#Override
public void hideCounterView() {
if (!counterAnimationInProgress && newPostsCounterTextView.getVisibility() == View.VISIBLE) {
counterAnimationInProgress = true;
AlphaAnimation alphaAnimation = AnimationUtils.hideViewByAlpha(newPostsCounterTextView);
alphaAnimation.setAnimationListener(new Animation.AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
}
#Override
public void onAnimationEnd(Animation animation) {
counterAnimationInProgress = false;
newPostsCounterTextView.setVisibility(View.GONE);
}
#Override
public void onAnimationRepeat(Animation animation) {
}
});
alphaAnimation.start();
}
}
#SuppressLint("RestrictedApi")
#Override
public void openPostDetailsActivity(Post post, View v) {
Intent intent = new Intent(MainActivity.this, PostDetailsActivity.class);
intent.putExtra(PostDetailsActivity.POST_ID_EXTRA_KEY, post.getId());
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
View imageView = v.findViewById(R.id.postImageView);
View authorImageView = v.findViewById(R.id.authorImageView);
ActivityOptions options = ActivityOptions.
makeSceneTransitionAnimation(MainActivity.this,
new android.util.Pair<>(imageView, getString(R.string.post_image_transition_name)),
new android.util.Pair<>(authorImageView, getString(R.string.post_author_image_transition_name))
);
startActivityForResult(intent, PostDetailsActivity.UPDATE_POST_REQUEST, options.toBundle());
} else {
startActivityForResult(intent, PostDetailsActivity.UPDATE_POST_REQUEST);
}
}
public void showFloatButtonRelatedSnackBar(int messageId) {
showSnackBar(floatingActionButton, messageId);
}
#Override
public void openCreatePostActivity() {
Intent intent = new Intent(this, CreatePostActivity.class);
startActivityForResult(intent, CreatePostActivity.CREATE_NEW_POST_REQUEST);
}
#SuppressLint("RestrictedApi")
#Override
public void openProfileActivity(String userId, View view) {
Intent intent = new Intent(MainActivity.this, ProfileActivity.class);
intent.putExtra(ProfileActivity.USER_ID_EXTRA_KEY, userId);
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && view != null) {
View authorImageView = view.findViewById(R.id.authorImageView);
ActivityOptions options = ActivityOptions.
makeSceneTransitionAnimation(MainActivity.this,
new android.util.Pair<>(authorImageView, getString(R.string.post_author_image_transition_name)));
startActivityForResult(intent, ProfileActivity.CREATE_POST_FROM_PROFILE_REQUEST, options.toBundle());
} else {
startActivityForResult(intent, ProfileActivity.CREATE_POST_FROM_PROFILE_REQUEST);
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main_menu, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.profile:
presenter.onProfileMenuActionClicked();
return true;
case R.id.followingPosts:
Intent followingPosts = new Intent(this, FollowingPostsActivity.class);
startActivity(followingPosts);
return true;
case R.id.search:
Intent searchIntent = new Intent(this, SearchActivity.class);
startActivity(searchIntent);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}

Related

Webview app to check for network and display "no internet connection" if there is none and also reload when network is available

I created a simple webview app that displays an error.html from assets when there is no network, but users cannot continue with webview once network is available. users are simply stuck in the error.html page. what i have been trying to do now is to make the webview app to check for network and display "no internet connection" if there is none and also reload when network is available.
Manifest.xml
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mary">
<uses-permission android:name="android.permission.INTERNET" />
<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:theme="#android:style/Theme.Holo.Light">
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Splash"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
MainActivity.java
private WebView mWebView;
SwipeRefreshLayout swipe;
private void setFullScreen() {
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN
);
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
swipe = (SwipeRefreshLayout) findViewById(R.id.swipe);
swipe.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
#Override
public void onRefresh() {
LoadWeb(mWebView.getUrl());
}
});
LoadWeb("http://m.mary.org");
}
public void LoadWeb(String url){
mWebView = (WebView) findViewById(R.id.activity_main_webview);
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
mWebView.loadUrl(url);
swipe.setRefreshing(true);
mWebView.setDownloadListener(new DownloadListener() {
#Override
public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
DownloadManager.Request myRequest = new DownloadManager.Request(Uri.parse(url));
myRequest.allowScanningByMediaScanner();
myRequest.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
DownloadManager myManager = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
myManager.enqueue(myRequest);
Toast.makeText(MainActivity.this, "Your File is downloading....", Toast.LENGTH_SHORT).show();
}});
mWebView.setWebViewClient(new com.example.mary.MyAppWebViewClient(){
public void onReceivedError(WebView view, int errorCode, String description,String failingUrl) {
mWebView.loadUrl("file:///android_asset/error.html");
}
public void onPageFinished(WebView view, String url) {
//hide loading image
swipe.setRefreshing(false);
//show webview
findViewById(R.id.activity_main_webview).setVisibility(View.VISIBLE);
}});
}
#Override
public void onBackPressed() {
if(mWebView.canGoBack()) {
mWebView.goBack();
} else {
super.onBackPressed();
}
}
}
MyAppWebViewClient.java
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if(Uri.parse(url).getHost().endsWith("m.mary.org")) {
return false;
}
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
view.getContext().startActivity(intent);
return true;
}
create a broadcast receiver :
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import java.util.HashSet;
import java.util.Set;
public class NetworkStateReceiver extends BroadcastReceiver {
protected Set<NetworkStateReceiverListener> listeners;
protected Boolean connected;
public NetworkStateReceiver() {
listeners = new HashSet<NetworkStateReceiverListener>();
connected = null;
}
public void onReceive(Context context, Intent intent) {
if(intent == null || intent.getExtras() == null)
return;
ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo ni = manager.getActiveNetworkInfo();
if(ni != null && ni.getState() == NetworkInfo.State.CONNECTED) {
connected = true;
} else if(intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY,Boolean.FALSE)) {
connected = false;
}
notifyStateToAll();
}
private void notifyStateToAll() {
for(NetworkStateReceiverListener listener : listeners)
notifyState(listener);
}
private void notifyState(NetworkStateReceiverListener listener) {
if(connected == null || listener == null)
return;
if(connected == true)
listener.networkAvailable();
else
listener.networkUnavailable();
}
public void addListener(NetworkStateReceiverListener l) {
listeners.add(l);
notifyState(l);
}
public void removeListener(NetworkStateReceiverListener l) {
listeners.remove(l);
}
public interface NetworkStateReceiverListener {
public void networkAvailable();
public void networkUnavailable();
}
}
in your activity use it like this :
private NetworkStateReceiver.NetworkStateReceiverListener networkStateReceiverListener = new NetworkStateReceiver.NetworkStateReceiverListener() {
#Override
public void networkAvailable() {
//todo: refresh webview
}
#Override
public void networkUnavailable() {
//todo: show error
}
};
permission in manifest:
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

Fail to load image from Uri in third activity

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>

Activity refresh after change activity

I have 3 Activity. 1 - MainActivity , 2 - InfoActivity, 3 - ChangelogActivity.
If i am located on InfoActivity all is good (on InfoActivity placed ProgressBar) , if i go to ChangelogActivity and go back again to InfoActivity ProgressBar work fine, and his value not 0, but if i go to MainActivity from InfoActivity and go back, now ProgerssBar get value 0.
How i can fix it?
If need i can place some code here.
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.teammt.gmanrainy.huaweifirmwarefinder">
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_SUPERUSER" />
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:configChanges="orientation|screenSize|keyboardHidden|uiMode">
android:screenOrientation="portrait"
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".FirmwareInfo"
android:configChanges="orientation|screenSize|keyboardHidden|uiMode"
android:screenOrientation="portrait" />
<activity
android:name=".FirmwareChangelog"
android:configChanges="orientation|screenSize|keyboardHidden|uiMode"
android:screenOrientation="portrait" />
<activity android:name=".SettingsActivity"
android:configChanges="orientation|screenSize|keyboardHidden|uiMode"
android:screenOrientation="portrait"></activity>
</application>
</manifest>
MainActivity Overrided Methods
//Действия во время созданиея MainActivity
#Override
protected void onCreate(Bundle savedInstanceState) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
//Конструктор Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Проверка прав
ActivityCompat.requestPermissions(this, PERMISSION_STRING_ARRAY, REQUEST_PERMISSION_PHONE_STATE);
//Инициализация
utils = new FFUtils();
gridView = (GridView) findViewById(R.id.firmware_grid_view);
//Установка модели в тайтл
if(deviceModel != null)
setTitle(deviceModel);
else
setTitle(getString(R.string.app_name));
///////////////////////////////////////
// Advanced listener блок
///////////////////////////////////////
//Клик по элементу GridView
gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View v, int position, long id)
{
try
{
System.out.println(lastFirmwares.get(position));
String[] lastFirmwareArray = lastFirmwares.get(position).split("\\|");
Intent intent = new Intent(getThis(), FirmwareInfo.class);
intent.putExtra("firmwareName",lastFirmwareArray[0]).
putExtra("firmwareType",lastFirmwareArray[1]).
putExtra("firmwareLink",lastFirmwareArray[2]).
putExtra("firmwareSize",lastFirmwareArray[3]).
putExtra("firmwareLastmod",lastFirmwareArray[4]).
putExtra("firmwareCount",lastFirmwares.size()).
putExtra("firmwareId",position);
startActivity(intent);
}
catch (Exception ex)
{
Log.e("GetFirmwarePosition",ex.getMessage());
}
}
});
}
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
}
#Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putBundle("newBundy", newBundy);
}
#Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
savedInstanceState.getBundle("newBundy");
}
//Действия после загрузки формы
#Override
protected void onStart() {
super.onStart();
getDelegate().onStart();
//Получаем список моделей
modelsList = utils.getModelsList(MODELSLIST_LINK);
//Получаем приведенную к общему виду модель
if(modelManuallyChanged == false)
deviceModel = utils.getDeviceModel(modelsList,utils.getDeviceFullModel());
//Добавляем модель в тайтл
setTitle(deviceModel);
}
InfoActivity Overrided Methods
//Действия во время созданиея FirmwareInfo
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_firmware_info);
this.setTitle("FirmwareInfo");
//Инициализация
utils = new FFUtils();
firmware_info_lastmod_textview = (TextView)findViewById(R.id.firmware_info_lastmod_textview);
firmware_info_size_textview = (TextView) findViewById(R.id.firmware_info_size_textview);
firmware_info_download_progressbar = (ProgressBar) findViewById(R.id.firmware_info_download_progressbar);
//firmware_info_download_progressbar.setProgress(0);
//Убираем тень
getSupportActionBar().setElevation(0);
}
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
}
#Override
public void onSaveInstanceState(Bundle savedInstanceState) {
super.onSaveInstanceState(savedInstanceState);
savedInstanceState.putInt("progressbar_progress", firmware_info_download_progressbar.getProgress());
}
#Override
public void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
int progressbar_progress = savedInstanceState.getInt("progressbar_progress");
firmware_info_download_progressbar.setProgress(progressbar_progress);
}
//Действия после загрузки формы
#Override
protected void onStart() {
super.onStart();
getDelegate().onStart();
firmwareName = getIntent().getExtras().getString("firmwareName");
firmwareType = getIntent().getExtras().getString("firmwareType");
firmwareLink = getIntent().getExtras().getString("firmwareLink");
firmwareSize = getIntent().getExtras().getString("firmwareSize");
firmwareLastmod = getIntent().getExtras().getString("firmwareLastmod");
firmwareId = getIntent().getExtras().getInt("firmwareId");
firmwareCount = getIntent().getExtras().getInt("firmwareCount");
if(firmwareName != null)
{
setTitle(firmwareName + " " + firmwareType);
firmware_info_lastmod_textview.setText(getString(R.string.last_mod) + " " + firmwareLastmod);
firmware_info_size_textview.setText(getString(R.string.size) + " " + utils.convertToMegabyte(firmwareSize));
}
}
Changelog Overrided Methods
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_firmware_changelog);
//Инициализация
utils = new FFUtils();
firmware_changelog_view_model = (TextView)findViewById(R.id.firmware_changelog_view_model);
firmware_changelog_view_changelog = (TextView)findViewById(R.id.firmware_changelog_view_changelog);
firmware_changelog_view_changelog.setMovementMethod(new ScrollingMovementMethod());
//Убираем тень
getSupportActionBar().setElevation(0);
//Убираем Titile
getSupportActionBar().hide();
}
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
}#Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putBundle("newBundy", newBundy);
}
#Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
savedInstanceState.getBundle("newBundy");
}
//Действия после загрузки формы
#Override
protected void onStart() {
super.onStart();
getDelegate().onStart();
firmwareName = getIntent().getExtras().getString("firmwareName");
firmwareType = getIntent().getExtras().getString("firmwareType");
firmwareLink = getIntent().getExtras().getString("firmwareLink");
firmwareSize = getIntent().getExtras().getString("firmwareSize");
firmwareLastmod = getIntent().getExtras().getString("firmwareLastmod");
firmware_changelog_view_model.setText(firmwareName);
Thread t = new Thread(new Runnable() {
#Override
public void run() {
try
{
//Получаем List со всеми строками feature из changelog
parsedChangelog = parseXmlString(prepareXpp(utils.getXmlFromUrl(firmwareLink.replace("update.zip","changelog.xml"))));
}
catch (Exception ex)
{
Log.e("Parse error",ex.getMessage());
}
StringBuilder sb = new StringBuilder();
for (String s : parsedChangelog)
{
sb.append(s);
sb.append("\t");
}
utils.universalSetText(firmware_changelog_view_changelog,sb.toString());
//firmware_changelog_view_changelog.setText(sb.toString());
}
});
t.start();
}

app crashing when switching activities

Hi so I have been going at this for days and I keep getting a crash everytime I try to move into my list view activity. I have rewritten the list view activity twice here is the activity code:
protected List<ParseObject> exercise_name;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_exersise_display);
ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("Exercises");
query.findInBackground(new FindCallback<ParseObject>() {
#Override
public void done(List<ParseObject> list, ParseException e) {
if(e==null){
//success
exercise_name = list;
Excercise_Adapter adapter = new Excercise_Adapter(getListView().getContext(), exercise_name);
setListAdapter(adapter);
}
else {
}
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_exersise__display, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
here is the Exercise Adapter class
protected Context mContext;
protected List mExercise;
public Excercise_Adapter (Context context, List exercise){
super(context, R.layout.da_excerisises, exercise);
mContext = context;
mExercise = exercise;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if(convertView == null){
convertView = LayoutInflater.from(mContext).inflate(R.layout.da_excerisises, null);
holder = new ViewHolder();
//holder.exerciseImage = (ImageView)convertView.findViewById(R.id.Exersise_image);
holder.exerciseName = (TextView) convertView.findViewById(R.id.Exersise_name_menu);
convertView.setTag(holder);
}
else{
holder = (ViewHolder)convertView.getTag();
}
ParseObject exercise_object = mExercise.get(position);
String title = exercise_object.getString("exercise_name");
holder.exerciseName.setText(title);
return convertView;
}
public static class ViewHolder{
//ImageView exerciseImage;
TextView exerciseName;
}
and here is the calling code:
protected Button fitcalcmain;
protected Button excersise;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Parse.initialize(this, "BEFmOu6ru7ulUKCaFaNP8JdGU73RBc4wFfvOjfWp", "dV460EGCxMwhzvRhHQDne2zlYoeOQu2aDypfuTTW");
fitcalcmain = (Button)findViewById(R.id.FitnessCalcMain);
excersise = (Button)findViewById(R.id.ExersisesMain);
fitcalcmain.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent gomeasure = new Intent(MainActivity.this, fitcalc.class);
startActivity(gomeasure);
}
});
excersise.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent goexcercises = new Intent(MainActivity.this, Exersise_Display.class);
startActivity(goexcercises);
}
});
}
here is the log (sorry it doesn't let me paste it into here because of "bad formatting":google doc with logcat
XML file of activity:
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/list"
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true" />
here is the manifest
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="Workout Buddy"
android:theme="#style/AppTheme" >
<activity
android:name=".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>
<activity
android:name=".MainActivity"
android:label="#string/Mainmenu" >
</activity>
<activity
android:name=".RegisterActivity"
android:label="#string/app_name" >
</activity>
<activity
android:name=".fitcalc"
android:label="#string/title_activity_fitcalc" >
</activity>
<activity
android:name=".Exersise_Display"
android:label="#string/title_activity_exersise__display" >
</activity>
<activity
android:name=".Types_Activity"
android:label="#string/title_activity_types_" >
</activity>
</application>
You should return convertView in your adapter getView instead of calling super. Plus if this didnt help you please post the code to start your activity.
edit
Please add the two of your activities into the manifest inside of application tag ex:
<activity android:name="myActivity">
<activity android:name="myActivity"Two>

Starting a new intent with FragmentsActivity - crashes

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>

Categories