Можно ли снова показывать popupWindow в Android после одного увольнения?Я не могу это сделать - PullRequest
0 голосов
/ 27 декабря 2018

У меня есть активность в моем проекте Android.При нажатии на кнопку появляется всплывающее окно.Все идет хорошо, пока я не нажму обратно в popupWindow, не вернусь к активности и снова не нажму кнопку.Все зависает и приложение останавливается.

У моего popupWindow есть настроенный вид.Его представление состоит из SearchView, ExpandableListView и кнопки для отправки.РасширяемыйСписок извлекает телефонные контакты.Я искал проблему, но у них были проблемы с увольнением при нажатой спине, с чем я не имею дело.

Button import_contact = findViewById(R.id.import_contact);
import_contact.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
    LayoutInflater inflater = (LayoutInflater)
    getSystemService(LAYOUT_INFLATER_SERVICE);
    View popupView = inflater.inflate(R.layout.import_contacts_window, null);
    int width = LinearLayout.LayoutParams.MATCH_PARENT;
    int height = LinearLayout.LayoutParams.MATCH_PARENT;
    PopupWindow popupWindow = new PopupWindow(popupView, width, height, true);
    popupWindow.setOutsideTouchable(true);
    popupWindow.setBackgroundDrawable(new ColorDrawable(Color.GRAY));
    popupWindow.setContentView(popupView);
    popupWindow.showAtLocation(findViewById(R.id.contacts_container), Gravity.CENTER, 0, 0);
    popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
        @Override
        public void onDismiss() {
            Log.e("dismiss", "true");
        }
    });

    contactsListView = popupView.findViewById(R.id.phone_contacts_list);
    contactsListDataAdapter = new ContactListAdapter(MainActivity.this,
                                expandableListTitle,
                                expandableListDetail);
    DisplayMetrics metrics = new DisplayMetrics();                    
    getWindowManager().getDefaultDisplay().getMetrics(metrics);
    int w = metrics.widthPixels;
    contactsListView.setIndicatorBounds(w - 30, w - 6);                    
    contactsListView.setAdapter(contactsListDataAdapter);
    SearchManager searchManager = (SearchManager) 
    getSystemService(Context.SEARCH_SERVICE);
    search = popupView.findViewById(R.id.searchContacts);
    search.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    search.setIconifiedByDefault(false);
    search.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            Log.e("onQueryTextSubmit", "1");
            return false;
        }
        @Override
        public boolean onQueryTextChange(String newText) {
            Log.e("onQueryTextChange", " ");
            contactsListDataAdapter.filterData(newText);
            expandAll();
            return true;
        }
    });
    search.setOnCloseListener(new SearchView.OnCloseListener() {
        @Override
        public boolean onClose() {
            Log.e("onClose", " ");
            return false;
        }
    });
    Button OK = popupView.findViewById(R.id.OK);
    OK.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
        // TODO: verify OK from Client with a popup dialog
        }
    });
    if (!hasPhoneContactsPermission(Manifest.permission.READ_CONTACTS)) {                    
        requestPermission(Manifest.permission.READ_CONTACTS, PERMISSION_REQUEST_CODE_READ_CONTACTS);
    } else {
        readPhoneContacts();
    }
}
});

Вот журнал после закрытия всплывающего окна и после того, как я нажал кнопку, чтобыснова откройте popupWindow:

12-27 03:57:31.925 16287-16287/com.ghasedakia E/dismiss: true
12-27 03:57:31.925 16287-16287/com.ghasedakia W/InputEventReceiver: 
Attempted to finish an input event but the input event receiver has already 
been disposed.
12-27 03:57:50.765 151-179/? W/AudioPolicyManagerBase: getOutput() could not 
find output for stream 1, samplingRate 0,format 0, channels 3, flags 0
12-27 03:57:50.765 151-151/? W/AudioPolicyManagerBase: getOutput() could not 
find output for stream 1, samplingRate 0,format 0, channels 3, flags 0
12-27 03:57:50.765 151-11050/? W/AudioPolicyManagerBase: getOutput() could 
not find output for stream 1, samplingRate 44100,format 1, channels 1, flags 
4
12-27 03:57:50.765 313-426/system_process E/AudioTrack: Could not get audio 
output for stream type 1
12-27 03:57:50.765 313-426/system_process E/SoundPool: Error creating 
AudioTrack
12-27 03:57:50.905 493-496/com.android.phone D/dalvikvm: GC_CONCURRENT freed 
384K, 6% free 11238K/11847K, paused 0ms+0ms, total 2ms

Через некоторое время приложение упало со следующим журналом:

12-27 04:34:12.977 313-392/system_process I/InputDispatcher: Application is 
not responding: Window{53799ea0 com.ghasedakia/com.ghasedakia.MainActivity 
paused=false}.  It has been 5003.3ms since event, 5003.3ms since wait started.  
Reason: Waiting because the touched window has not finished processing the input 
events that were previously delivered to it.
12-27 04:34:12.977 313-392/system_process I/WindowManager: Input event 
dispatching timed out sending to com.ghasedakia/com.ghasedakia.MainActivity
12-27 04:34:12.981 313-392/system_process I/Process: Sending signal. PID: 16861 
SIG: 3
12-27 04:34:12.989 16861-16866/com.ghasedakia I/dalvikvm: threadid=3: reacting 
to signal 3
12-27 04:34:12.989 313-316/system_process D/dalvikvm: GC_CONCURRENT freed 784K, 
15% free 13983K/16391K, paused 1ms+1ms, total 10ms
12-27 04:34:13.001 16861-16866/com.ghasedakia I/dalvikvm: Wrote stack traces to 
'/data/anr/traces.txt'
12-27 04:34:13.005 313-392/system_process I/Process: Sending signal. PID: 313     
SIG: 3
12-27 04:34:13.005 313-318/system_process I/dalvikvm: threadid=3: reacting to 
signal 3
12-27 04:34:13.077 313-325/system_process E/Sensors: Select fail, disconnect all 
clients (errno=4)
12-27 04:34:13.089 313-318/system_process I/dalvikvm: Wrote stack traces to 
'/data/anr/traces.txt'
12-27 04:34:13.113 313-392/system_process I/Process: Sending signal. PID: 493 
SIG: 3
12-27 04:34:13.113 493-500/com.android.phone I/dalvikvm: threadid=3: reacting to 
signal 3
12-27 04:34:13.113 313-316/system_process D/dalvikvm: GC_CONCURRENT freed 42K, 
15% free 13941K/16391K, paused 11ms+11ms, total 26ms
12-27 04:34:13.141 493-500/com.android.phone I/dalvikvm: Wrote stack traces to 
'/data/anr/traces.txt'
12-27 04:34:13.141 313-392/system_process I/Process: Sending signal. PID: 432 
SIG: 3
12-27 04:34:13.141 432-437/com.android.systemui I/dalvikvm: threadid=3: reacting 
to signal 3
12-27 04:34:13.153 432-437/com.android.systemui I/dalvikvm: Wrote stack traces 
to '/data/anr/traces.txt'
12-27 04:34:13.201 313-316/system_process D/dalvikvm: GC_CONCURRENT freed 521K, 
14% free 14148K/16391K, paused 12ms+1ms, total 24ms
12-27 04:34:13.201 313-392/system_process D/dalvikvm: WAIT_FOR_CONCURRENT_GC 
blocked 12ms
12-27 04:34:13.205 313-392/system_process D/dalvikvm: GC_EXPLICIT freed 17K, 14% 
free 14131K/16391K, paused 0ms+1ms, total 8ms
12-27 04:34:13.713 313-392/system_process E/ActivityManager: ANR in 
com.ghasedakia (com.ghasedakia/.MainActivity)
Reason: keyDispatchingTimedOut
        Load: 0.69 / 0.34 / 0.45
        CPU usage from 7981ms to 0ms ago:
        99% 16861/com.ghasedakia: 99% user + 0% kernel
        100% TOTAL: 99%   user + 0.2% kernel
        CPU usage from  227ms to 731ms later:
        94% 16861/com.ghasedakia: 94% user + 0% kernel
        94% 16861/com.ghasedakia: 94% user + 0% kernel
        100% TOTAL: 100%   user + 0% kernel
12-27 04:34:13.749 313-316/system_process D/dalvikvm: GC_CONCURRENT freed 412K, 
12% free 14568K/16391K, paused 12ms+1ms, total 27ms
12-27 04:34:13.749 313-16887/system_process D/dalvikvm: WAIT_FOR_CONCURRENT_GC 
blocked 16ms
12-27 04:34:13.757 313-16887/system_process D/dalvikvm: GC_FOR_ALLOC freed 459K, 
13% free 14275K/16391K, paused 9ms, total 9ms
12-27 04:34:16.081 313-325/system_process D/Sensors: Client connection accepted 
(232)

Я видел эту страницу, https://blog.csdn.net/geekqian/article/details/70279076

Iдумаю проблема такая же как у меня.Но я не могу setFocusable в false, потому что мне нужно обрабатывать щелчки на моем popupWindow.

Я ожидаю, что каждый раз, когда происходит нажатие на кнопку, будет отображаться всплывающее окно.Но второй раз, когда я нажимаю кнопку, приложение зависает.Есть идеи, где проблема?

...