Huawei Map suddenly unable to load and crash - huawei-mobile-services

The map was working right before suddenly started to crash on activity open.
The code was same as working and no changes made. what coul be the problem?
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
mapView = findViewById(R.id.map);
checkPermission();
if (permission) {
mapView.getMapAsync(this);
mapView.onCreate(savedInstanceState);
}
}
#Override protected void onStart() { super.onStart(); mMapView.onStart(); }
#Override protected void onResume() { super.onResume(); mMapView.onResume(); }
#Override protected void onPause() { super.onPause(); mMapView.onPause(); }
#Override protected void onStop() { super.onStop(); mMapView.onStop(); }
#Override protected void onDestroy() { super.onDestroy(); mMapView.onDestroy(); }
#Override public void onLowMemory() { super.onLowMemory(); mMapView.onLowMemory(); }

When the code did not change, it could be that the permission of app changed.
perhaps it was reinstalled and uninstalled?
looking at the code, the oncreate is called after permission check.
we need to either ask for permission again, or have the app proceed without map. one of two choices.
This should prevent NullPointerException.
also for permission request, we need to handle SecurityException to avoid crashing.

Related

Unsubscribing from RxJava2/RxAndroid PublishSubject

I'm trying to replace EventBus with RxAndroid.
I want pageable fragments to subscribe/unsubscribe to an event source, these fragments get created and discarded relatively quickly, depending on how fast the user slides to a new page.
In EventBus I was able to add an decorated callback method (ie #Subscribe(threadMode = ThreadMode.MAIN)) and register/unregister in the onStart/onStop methods of the fragment.
With RxJava2 I now create a PublishSubject object in a class
public static PublishSubject<List<Long>> m_psUpdatedDays = PublishSubject.create();
public static void publishUpdatedDays(List<Long> lDay) {
m_psUpdatedDays.onNext(lDay);
}
and subscribe to this publisher in another class by calling the following in the Fragment's onStart method:
m_psUpdatedDays.observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<List<Long>>() {
#Override public void onSubscribe(Disposable d) {}
#Override public void onNext(List<Long> longs) {
...
Update Fragment UI here
...
}
#Override public void onError(Throwable e) {}
#Override public void onComplete() {}
});
My question is how can I unsubscribe this new Observer when the Fragment's onStop method is called by the system?
Do I need to store the Disposable object which I get in the onSubscribe and then call .dispose() on it in the onStop method?
You can make use of a CompositeDisposable object, which can keep a list of disposables and all of them can be disposed together.
Create a CompositeDisposable instance in the base fragment level, keep on adding your disposables into it.
public abstract class BaseFragment extends Fragment {
protected CompositeDisposable mCompositeDisposable = new CompositeDisposable();
#Override
public void onPause() {
super.onPause();
mCompositeDisposable.clear();
//clear will clear all, but can accept new disposable.
// You can call it on `onPause` or `orDestroyView` events.
}
#Override
public void onDestroy() {
super.onDestroy();
mCompositeDisposable.dispose();
//dispose will clear all and set isDisposed = true, so it will not accept any new disposable
}
}
In your fragments, subscribe to the Observable using the subscribeWith method, which gives you a disposable instantly and this disposable you can dispose later in the onPause or onDestroy events (wherever you want)
public class MyFragment extends BaseFragment {
#Override
public void onStart() {
super.onStart();
Disposable disposable = m_psUpdatedDays.observeOn(AndroidSchedulers.mainThread())
.subscribeWith(new DisposableObserver<List<Long>>() { // Use `subscribeWith` instead of `subscribe`, which will give you back the disposable , which can be disposed later
#Override
public void onNext(List<Long> longs) {
// Update Fragment UI here
}
#Override
public void onError(Throwable e) {
}
#Override
public void onComplete() {
}
});
mCompositeDisposable.add(disposable); // add the disposable to the disposable list
}
}

GWT Array of checklist click handler not working

i have been trying to generate an array of check boxes and dynamic click handler for them but the handler is not working. Any suggestion will be most welcomed. Thanks in Advance for the time.
private void addButtonListener() {
goButton.addClickHandler(new ClickHandler() {
#SuppressWarnings("rawtypes")
#Override
public void onClick(ClickEvent arg0) {
String strQuery="Select BRANCH_NAME from SAMPLE_ACC_BRANCH where GL_CODE='"+gll_textfield.getText().trim()+"'";
HibernateImplUtils.getSearchResult(strQuery, new AsyncCallback() {
private int i;
#Override
public void onFailure(Throwable arg0)
{arg0.printStackTrace();}
#Override
public void onSuccess(Object arg0) {
System.err.println("Inside Success");
List branchNameList=(List) arg0;
System.err.println("Branch List:::"+branchNameList);
for(i=0;i<branchNameList.size();i++){
checkbox[i]=new CheckBox((String) branchNameList.get(i));
vpanel.add(checkbox[i]);
checkbox[i].addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent arg0) {
if(checkbox[i].getValue()){
System.out.println("NAME::::"+checkbox[i].getText());
}
System.out.println("Selected check box ::::"+checkbox[i].getText());
}
});
}
}
});
}
});
}
The scope of "i" is dodgy. Quickest fix would be to make a "final" copy for your event handler. e.g. "final int i2 = i"
The inner class probably wants the index value during its creation.
I'd be tempted to do use a final reference to the checkbox you create or the reference passed to the event handler (that way you could also use a single instance).
(Modified)
final int i2=i;
checkbox[i2].addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent arg0) {
if(checkbox[i2].getValue()){
System.out.println("NAME::::"+checkbox[i2].getText());
}
}
});

refresh listView by clicking outside of it

I have a viewpager with an adapter that extends FragmentStatePagerAdapter, this has to show some fragment that always repeats the same layout (in whic there is a listView) for every page ... now the problem is how can I update the listView that is currently visible by clicking on a button that is outside of the Fragment? I can refresh only the ones that are in the not visible pages,but not the ones that are displayed or adjacent...
One possible solution is to reset the adapter, but it doesn't seems to be right one, because it' s slow... could you please help me?
public class MainActivity extends FragmentActivity implements OnClickListener{
#Override
protected void onCreate(Bundle arg0) {
// TODO Auto-generated method stub
super.onCreate(arg0);
setContentView(R.layout.layout1);
pagerAdapter = new AdapterPager(getSupportFragmentManager());
ctx=this;
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(pagerAdapter);
pagerTab=(PagerTabStrip) findViewById(R.id.pager_tab_strip);
mViewPager.setCurrentItem(paginaCentrale);
modifica=(ImageView)findViewById(R.id.modifica);
modifica.setOnClickListener(this);
}
#Override
public void onClick(View arg0) {
// TODO onClick
switch (arg0.getId()){
case R.id.modifica:
//here I would like to call the method caricaLista() of the fragment
break;
}
}
public static class AdapterPager extends FragmentStatePagerAdapter {
public AdapterPager(FragmentManager fm) {
super(fm);
}
#Override
public int getItemPosition(Object object) {
// TODO Auto-generated method stub
return super.getItemPosition(object);
}
#Override
public Fragment getItem(int i) {
Fragment fragment;
Bundle args = new Bundle();
args.putInt("position", i);
fragment=new Fragment1();
fragment.setArguments(args);
return fragment;
}
#Override
public int getCount() {
return 1000;}
#Override
public CharSequence getPageTitle(int i) {
String title=String.valueOf(i);
return title;
}
}
public static class Fragment1 extends Fragment implements OnItemClickListener{
int fragmentPosition;
ListView lv;
List<Lista> lista= new ArrayList<Lista>();
public Fragment1(){
}
public static Fragment1 newInstance(){
return new Fragment1();
}
#Override
public void onResume() {
// TODO Auto-generated method stub
super.onResume();
caricaLista("")}
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle
savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment1, container, false);
lv=(ListView) rootView.findViewById(R.id.listViewCompiti);
Bundle args = getArguments();
int position= args.getInt("position");
fragmentPosition=position;
lv.setOnItemClickListener(this);
homeListAdapter= new HomeListAdapterWithCache(ctx,R.layout.list_item_home,lista);
lv.setAdapter(homeListAdapter);
return rootView;
}
You have to store the Current Fragment into your MainActivity , and change every time the page changes.
So you call the method of the current fragments.
Check out how your MainActivity should look like:
public class MainActivity extends FragmentActivity implements OnClickListener{
&Fragment mCurrentFragment;*
protected void onCreate(Bundle arg0) {
super.onCreate(arg0);
setContentView(R.layout.layout1);
pagerAdapter = new AdapterPager(getSupportFragmentManager());
ctx=this;
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(pagerAdapter);
pagerTab=(PagerTabStrip) findViewById(R.id.pager_tab_strip);
mViewPager.setCurrentItem(paginaCentrale);
modifica=(ImageView)findViewById(R.id.modifica);
modifica.setOnClickListener(this);
*mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
#Override
public void onPageSelected(int position) {
mCurrentFragment = pagerAdapter.getItem(position);
}*
});
#Override
public void onClick(View arg0) {
// TODO onClick
switch (arg0.getId()){
case R.id.modifica:
*mCurrentFragment.caricaLista();*
break;
}
}
}

smartgwt + gin Code Splitting

I am looking for example to use code splitting with gin and smartgwt ...
In my simple application I have 2 modules AutoLoadModule and WindowModule. In my simple app I just need to load a window when some button is clicked.
My window module contains:
#Override
protected void configure() {
bind(MainWindow.class).in(Singleton.class);
}
and my MainWindow:
#Singleton
public class MainWindow extends Window implements SessionStatusChangedEvent.Handler {
private final XmppSession session;
#Inject
private MainWindow(XmppSession session) {
Log.debug("Constructor ImMainWindow... !");
this.session = session;
initComponent();
}
....................
In my AutoLoadModule I have bind AutoLoad asEagerSingleton();
#Override
protected void configure() {
bind(StartButton.class).toProvider(StartChatButtonProvider.class);
bind(AutoLoader.class).asEagerSingleton();
}
My AutoLoader class:
#Singleton
public class AutoLoader implements Scheduler.ScheduledCommand {
private final XmppConnection connection;
#Nullable
private final ImStartButton startButton;
#Inject
protected AutoLoader(final XmppConnection connection, final XmppSession session,
final StartButton startButton) {
this.startButton = startButton;
Scheduler.get().scheduleDeferred(this);
}
#Override
public final void execute() {
startButton.addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
Log.debug("StartButton click handler...");
//load window in this point but how ? ....
}
});
}
}
Its possible to load a window instance using Code Splitting, when window is in WindowModule? In my example app I need load the window only on demand using code splitting and that window must be in a gin module.
Not sure where you want to split your code, but using gin you can take advantage of AsyncProviders and let git to split your code.
#Inject
protected AutoLoader(
final XmppConnection connection,
final XmppSession session,
final StartButton startButton,
final AsyncProvider<MainWindow> mainProvider) {
...
#Override
public final void execute() {
startButton.addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
// Here Gin would split the code
mainProvider.get(new AsyncCallback<MainWindow>() {
public void onSuccess(MainWindow main) {
...
}
}
}
});
}

GWT RPC mechanism how to use non void return type

I have a scenario wherein I need to specify a return type to the Synchrnous function, the code is as follows :
#RemoteServiceRelativePath("show_box")
public interface ShowBoxCommandService extends RemoteService{
public ArrayList<String> showBox();
}
The implementation of the method on the server is :
public ArrayList<String> showBox() {
ArrayList<String> box = new ArrayList<String>();
Iterator<Box> boxes = BoxRegistry.getInstance().getBoxes();
while (boxes.hasNext()) {
box.add(boxes.next().toString());
}
return box;
}
I am trying to define the callback variable in the following format at the client side in order to call the method
AsyncCallback<Void> callback = new AsyncCallback<Void>() {
public void onFailure(Throwable caught) {
// TODO: Do something with errors.
// console was not started properly
}
#Override
public void onSuccess(Void result) {
// TODO Auto-generated method stub
// dialog saying that the console is started succesfully
}
};
update with the aync interface code :
public interface ShowBoxCommandServiceAsync {
void showBox(AsyncCallback<ArrayList<String>> callback);
}
But this is causing the definition of the method in the Async method to change.
Any ideas or clues will be helpful.
Thanks,
Bhavya
P.S. Apologies if this is a repetition
The callback should be:
AsyncCallback<ArrayList<String>> callback = new AsyncCallback<ArrayList<String>>() {
public void onFailure(Throwable caught) {
// TODO: Do something with errors.
// console was not started properly
}
#Override
public void onSuccess(ArrayList<String> result) {
// TODO Auto-generated method stub
// dialog saying that the console is started succesfully
}
};
If you don't need to utilize the result then you can ignore it, but if that is the case, you should probably question your design and why you would need the method to return an ArrayList<String> in the first place.
If the service interface looks like this:
public interface ShowBoxCommandService extends RemoteService {
public ArrayList<String> showBox();
}
then you must have an associated async interface:
public interface ShowBoxCommandServiceAsync {
public void showBox(AsyncCallback<ArrayList<String>> callback);
}
Which means, that the type of the callback that you should pass to showBox is AsyncCallback<ArrayList<String>>.
new AsyncCallback<ArrayList<String>>() {
#Override
public void onSuccess(ArrayList<String> list) {
// ...
}
#Override
public void onFailure(Throwable caught) {
// ...
}
}
Your callback should not be Void. If your synchronous method returns a List of Strings, the async callback method should receive the List. You'll have to use the ArrayList, because the class needs to implement the Serializable interface.
AsyncCallback<ArrayList<String>> callback = new AsyncCallback<ArrayList<String>>() {
public void onFailure(Throwable caught) {
// TODO: Do something with errors.
// console was not started properly
}
#Override
public void onSuccess(ArrayList<String> result) {
// TODO Auto-generated method stub
// dialog saying that the console is started succesfully
}
};
Huh? Your method returns an ArrayList and you are declaring void in your call?
Change <Void> to <ArrayList<String>>